Azure Cosmos DB APIs Reference

Explore the various APIs available for Azure Cosmos DB, allowing you to interact with your data using different programming models and protocols.

SQL (Core) API

The SQL (Core) API is the foundational API for Azure Cosmos DB, offering a rich, schema-agnostic data model and powerful query capabilities using a familiar SQL syntax.

  • Key Features:
  • SQL query language support
  • Document-centric data model
  • JSON data format
  • Stored procedures, triggers, and UDFs

Learn More:

SQL API Overview | SQL API SDKs

Reference:

GET https://{database_account_name}.documents.azure.com/dbs
Host: {database_account_name}.documents.azure.com
Content-Type: application/json
x-ms-date: Tue, 26 Mar 2024 22:07:17 GMT
Authorization: type="master", ...

MongoDB API

The MongoDB API allows you to use the popular MongoDB drivers and tools with Azure Cosmos DB. It provides compatibility with MongoDB applications without requiring code changes.

  • Key Features:
  • Compatibility with MongoDB wire protocol
  • Support for MongoDB drivers and SDKs
  • NoSQL document database
  • Scalability and global distribution

Learn More:

MongoDB API Overview | MongoDB API SDKs

Reference:

db.collection.find({})

Cassandra API

The Cassandra API provides a turn-key Apache Cassandra solution with no operational burden. It's designed for applications requiring high availability and massive throughput.

  • Key Features:
  • Apache Cassandra compatibility
  • CQL (Cassandra Query Language) support
  • High throughput and low latency
  • Global distribution

Learn More:

Cassandra API Overview | Cassandra API SDKs

Reference:

SELECT * FROM users WHERE id = ?

Table API

The Table API is ideal for storing and querying large amounts of structured, non-relational data. It offers a key-value store and is compatible with Azure Table Storage.

  • Key Features:
  • Key-value store
  • Schema-less design
  • High scalability
  • Simple query patterns

Learn More:

Table API Overview | Table API SDKs

Reference:

$table = "MyTable"
$query = New-Object Microsoft.Azure.Cosmos.Table.TableQuery `
    -ArgumentList $table
$entities = $tableContext.ExecuteQuery($query)

Gremlin API

The Gremlin API enables you to work with graph data using the Apache TinkerPop Gremlin query language. It's perfect for building connected data applications.

  • Key Features:
  • Graph database capabilities
  • Apache TinkerPop Gremlin support
  • Traversal-based querying
  • Relationship-rich data modeling

Learn More:

Gremlin API Overview | Gremlin API SDKs

Reference:

g.V().has('name', 'Alice')

Choosing the Right API

Azure Cosmos DB supports multiple data models and APIs. The best API for your application depends on your specific requirements:

  • For new cloud-native applications needing flexible querying, the SQL API is often the best choice.
  • If you have existing MongoDB applications, the MongoDB API offers seamless migration.
  • For applications requiring high throughput and Cassandra compatibility, the Cassandra API is suitable.
  • For simpler key-value storage needs and compatibility with Azure Table Storage, the Table API is a good option.
  • If your application deals with complex relationships and network data, the Gremlin API is designed for graph data.