Cosmos DB APIs: SQL, MongoDB & More
Cosmos DB isn't one database — it's a platform that speaks multiple languages. Choose the API that matches your data model and developer skills.
One engine, multiple APIs
Cosmos DB is like a restaurant that serves multiple cuisines.
The kitchen (engine) is the same, but you can order from different menus: Italian (SQL API), Japanese (MongoDB), Indian (Gremlin graph), or Chinese (Table). Each menu offers different dishes (data models), but they all come from the same high-quality kitchen.
You choose the API (menu) that matches what your application already expects.
The Cosmos DB APIs
API for NoSQL (formerly SQL API)
The default and most popular Cosmos DB API. Stores data as JSON documents and queries them using a SQL-like syntax.
SELECT c.name, c.email
FROM customers c
WHERE c.city = 'Auckland'
Best for: New applications, flexible document storage, developers who know SQL. Data model: JSON documents.
API for MongoDB
Uses the MongoDB wire protocol — existing MongoDB applications can connect to Cosmos DB with minimal code changes.
Best for: Migrating existing MongoDB apps to a fully managed, globally distributed service. Data model: BSON documents (MongoDB’s binary JSON).
API for Apache Cassandra
Compatible with the Apache Cassandra wire protocol. Supports CQL (Cassandra Query Language).
Best for: Migrating Cassandra workloads, wide-column data (IoT, time-series). Data model: Column-family (wide-column).
API for Table
Compatible with Azure Table Storage — but with Cosmos DB’s performance and global distribution.
Best for: Migrating from Azure Table Storage when you need better performance, global distribution, or automatic indexing. Data model: Key-value entities with flexible properties.
API for Apache Gremlin
Supports the Apache Gremlin graph traversal language for graph databases.
Best for: Social networks, recommendation engines, fraud detection — any data with complex relationships between entities. Data model: Nodes (entities) and edges (relationships) — graph.
| Feature | NoSQL (SQL) | MongoDB | Cassandra | Table | Gremlin |
|---|---|---|---|---|---|
| Data model | Documents (JSON) | Documents (BSON) | Column-family | Key-value | Graph |
| Query language | SQL-like | MQL | CQL | OData/REST | Gremlin |
| Best for | New apps | MongoDB migration | Cassandra migration | Table Storage upgrade | Connected data |
| Most popular? | Yes (default) | Second most | Niche | Niche | Niche |
How to choose an API
Simple decision tree:
- Building a new app? → API for NoSQL (most flexible, SQL-like queries)
- Migrating a MongoDB app? → API for MongoDB
- Migrating a Cassandra app? → API for Apache Cassandra
- Need graph traversal (social networks, recommendations)? → API for Gremlin
- Upgrading from Azure Table Storage? → API for Table
Important: Once you create a Cosmos DB account with a specific API, all databases in that account use that API. You can’t mix APIs within one account.
Exam tip: API matching
The exam gives you a scenario and asks which Cosmos DB API to use:
- “New application storing JSON documents” → NoSQL (SQL API)
- “Existing MongoDB application moving to Azure” → MongoDB API
- “Social network with users connected by friendships” → Gremlin API
- “Wide-column data from IoT sensors” → Cassandra API
- “Upgrading from Azure Table Storage” → Table API
The default choice for new applications is always NoSQL (SQL API) unless the scenario specifically mentions a different database technology.
Flashcards
Knowledge check
Aisha's university project involves analysing student collaboration patterns — who works with whom, which project groups overlap, and who the most connected students are. Which Cosmos DB API should she use?
A company is migrating their existing MongoDB application to Azure. They want to keep using MongoDB drivers and queries. Which Cosmos DB API provides the smoothest migration?
🎬 Video coming soon
Next up: Choosing Non-Relational Storage — a decision guide for all non-relational Azure services.