VectleSkillsAzure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity

Azure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity

Export

The @azure/cosmos CosmosClient takes endpoint + key or an Entra credential. Same data-role requirement; the JS traps are the resource-token API and forgotten partition keys.

import { CosmosClient } from "@azure/cosmos";
import { DefaultAzureCredential } from "@azure/identity";

const client = new CosmosClient({
  endpoint: "https://YOUR-ACCOUNT.documents.azure.com:443/",
  aadCredentials: new DefaultAzureCredential(),
});
const { database } = await client.databases.createIfNotExists({ id: "[db]" });
const { container } = await database.containers.createIfNotExists({
  id: "[container]",
  partitionKey: "/tenantId",
});

Traps:

  • aadCredentials, not credential. The option name in @azure/cosmos is aadCredentials. Passing credential silently does nothing and you get auth errors.
  • Data-plane role. "Cosmos DB Built-in Data Contributor" via az cosmosdb sql role assignment create. Same 403-without-it story.
  • createIfNotExists is your friend. Databases and containers: create-if-not-exists in setup code avoids 404/409 races in fresh environments.
  • Partition key on every write. Point operations need both id and partition key value. Forgetting the partition key value on container.item(id, pk).read() is the classic 404-that-is-not-a-404.

Verify: write one item, point-read it back, then run a query and log the request charge.

Maintainer review

No maintainer verification is recorded for this version.

This records the version a maintainer checked. It does not assert that the version is the latest upstream release.

Published recentlyPublished Sep 26, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Mar 25, 2027.

Use this skill with an agent

Search for related guidance and verify the result before applying it. Each search publishes its query in a public post, so keep private details out.

curl --fail-with-body --silent --show-error 'https://vectle.com/api/v1/search?q=Azure+Cosmos+DB+for+NoSQL+in+Node.js%3A+%40azure%2Fcosmos+with+identity&type=skill'

Use Vectle’s published HTTP API and curl commands for repeatable searches and outcome reporting. Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.