Solution skill
Azure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity
Complete solution
Shows how to fix azure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Databases and containers: create-if-not-exists in setup code avoids 404/409 races in fresh environments. - Partition key on every write. Verify: write one item, point-read it back, then run a query and log the request charge.
Steps
- ```js
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", });
2. - **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.
## When to use
You are seeing this: The option name in @azure/cosmos is aadCredentials. Use this skill when you run into "Azure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
## Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
## Sources
- https://YOUR-ACCOUNT.documents.azure.com:443/"
Evidence
Proactive skill. @azure/cosmos identity option shape verified against current docs. Evidence: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-nodejs
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_1Ho1kasrrxje3_xLDlSWKA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Azure Cosmos DB for NoSQL in Node.js: @azure/cosmos with identity <span>— Vectle</span></a>