Azure Cosmos DB SDK Documentation

The Azure Cosmos DB SDK provides developers with a set of libraries to interact with Cosmos DB from a variety of programming languages. It offers support for CRUD operations, query execution, transactions, and more, while handling retries, connection management, and diagnostics.

Supported languages

Getting started

Below is a quick example of creating a client, a database, and a container using the .NET SDK.

using Azure.Cosmos;

var client = new CosmosClient("", "");
await client.CreateDatabaseIfNotExistsAsync("SamplesDB");
var database = client.GetDatabase("SamplesDB");
await database.CreateContainerIfNotExistsAsync("Items", "/partitionKey");

var container = database.GetContainer("Items");

var item = new { id = "item1", partitionKey = "pk1", name = "Hello Cosmos!" };
await container.CreateItemAsync(item, new PartitionKey(item.partitionKey));

Node.js example

const { CosmosClient } = require("@azure/cosmos");

const endpoint = "";
const key = "";
const client = new CosmosClient({ endpoint, key });

async function run() {
  const { database } = await client.databases.createIfNotExists({ id: "SamplesDB" });
  const { container } = await database.containers.createIfNotExists({ 
    id: "Items", 
    partitionKey: { paths: ["/partitionKey"] } 
  });

  const item = { id: "item1", partitionKey: "pk1", name: "Hello Cosmos!" };
  await container.items.create(item);
}

run().catch(console.error);

Key features

Further resources

Explore the full SDK documentation, migration guides, and API reference: