Cosmos DB's other APIs and Azure DocumentDB — MongoDB (RU), DocumentDB (vCore) with Entra, Table, Cassandra and Gremlin
Which MongoDB-compatible or wire-protocol database to pick and how each authenticates — Azure DocumentDB (formerly Cosmos DB for MongoDB vCore) with Microsoft Entra users registered as mongoClusters/users and the MONGODB-OIDC driver flow from TypeScript, Cosmos DB for MongoDB (RU) with its error codes and 4-minute idle drop, Cosmos DB for Table's native data-plane roles, and where Microsoft now points Cassandra and Gremlin users.
markdownreferencev1TC9A-YQ8Nstage: designtrust: officialservice: cosmos-dbinterface: sdkinterface: cliAzure DocumentDBAzure Cosmos DB for MongoDB vCore renamedmongoClustersMicrosoft.DocumentDB/mongoClusters/usersauthConfig allowedModes NativeAuth MicrosoftEntraIDMONGODB-OIDCOIDC_CALLBACKALLOWED_HOSTS *.azure.commongocluster.cosmos.azure.comossrdbms-aad DocumentDBCosmos DB for MongoDB RUmongo.cosmos.azure.comMongo error 16500 TooManyRequestsMongo error 50 ExceededTimeLimitMongo error 13 UnauthorizedMongo error 11000 DuplicateKeyMongo error 61 ShardKeyNotFoundMongo error 2 BadValue indexmaxIdleTimeMS 120000appName=@accountName@Cosmos DB for Table RBACtables/containers/entitiesCosmos DB for Apache CassandraAzure Managed Instance for Apache CassandraCosmos DB for Apache GremlinGraph in Microsoft Fabric
Cosmos DB's other APIs and Azure DocumentDB
| Need | Microsoft points to |
|---|---|
| Migrate a MongoDB app, or use MQL features | Azure DocumentDB (vCore clusters, formerly Cosmos DB for MongoDB vCore, built on the open-source DocumentDB project) |
| Global scale, 99.999% SLA, instant autoscale | Cosmos DB for NoSQL (reference/cosmos-db/access-and-modeling.md) |
| Migrate an Apache Cassandra app | Azure Managed Instance for Apache Cassandra rather than Cosmos DB for Apache Cassandra |
| Graph analytics, or migrate a Gremlin app | Graph in Microsoft Fabric rather than Cosmos DB for Apache Gremlin |
Azure DocumentDB with Microsoft Entra
- Allow Entra alongside native users first (keep
NativeAuthuntil Entra sign-in works):authConfig.allowedModes: ['NativeAuth', 'MicrosoftEntraID']onMicrosoft.DocumentDB/mongoClusters(thedocumentdbCLI extension'smongocluster updatetakes--auth-allowed-modes). - Register each principal as a cluster user: a
Microsoft.DocumentDB/mongoClusters/usersresource named<cluster>/users/<object id>, withidentityProvider.type: MicrosoftEntraID, aprincipalTypeand roles such as{"db": "sales", "role": "readWrite"},readAnyDatabase,readWriteAnyDatabasewithclusterAdmin, or{"db": "admin", "role": "root"}. - Connect with
MONGODB-OIDC; the token audience is the same as PostgreSQL's and MySQL's,https://ossrdbms-aad.database.windows.net/.default.
import { MongoClient, type OIDCCallbackParams, type OIDCResponse } from "mongodb";
import { DefaultAzureCredential, type TokenCredential } from "@azure/identity";
const SCOPE = "https://ossrdbms-aad.database.windows.net/.default"; // same audience as PostgreSQL and MySQL
async function entraToken(_params: OIDCCallbackParams, credential: TokenCredential): Promise<OIDCResponse> {
const t = await credential.getToken(SCOPE);
if (!t) throw new Error("no token");
return { accessToken: t.token, expiresInSeconds: Math.floor((t.expiresOnTimestamp - Date.now()) / 1000) };
}
const credential = new DefaultAzureCredential();
// The identity must be registered as a cluster user (mongoClusters/users) with a role such as readWrite on the database.
export const client = new MongoClient(`mongodb+srv://${process.env.DOCUMENTDB_CLUSTER}.global.mongocluster.cosmos.azure.com/`, {
tls: true,
retryWrites: true,
connectTimeoutMS: 120_000,
authMechanism: "MONGODB-OIDC",
authMechanismProperties: {
OIDC_CALLBACK: (params: OIDCCallbackParams) => entraToken(params, credential),
ALLOWED_HOSTS: ["*.azure.com"],
},
});
export async function main(): Promise<void> {
await client.connect();
const orders = client.db("shop").collection<{ _id: string; customerId: string; total: number }>("orders");
await orders.updateOne({ _id: "o-1001" }, { $set: { customerId: "c-42", total: 12.5 } }, { upsert: true });
console.log(await orders.findOne({ _id: "o-1001" }));
await client.close();
}
Deleting a principal in Entra doesn't remove the cluster user, and issued tokens stay valid until they expire (up to about 90 minutes): delete the users/<object id> resource to revoke at once. Storage can grow but never shrink. Some server-side MongoDB extensions and storage engines aren't supported.
Cosmos DB for MongoDB (RU)
Endpoints are <account>.mongo.cosmos.azure.com (3.6 and later; 3.2 accounts used documents.azure.com), TLS 1.2. Its RBAC (users and roles, 3.6+) is managed only with the CLI or PowerShell.
| Code | Meaning → fix |
|---|---|
| 16500 TooManyRequests | RUs exhausted: retry, scale, or enable server-side retry |
| 50 ExceededTimeLimit | Past the 60-second limit: more RUs, smaller requests; retried writes can duplicate |
| 13 Unauthorized | Wrong key or missing permission |
| 11000 DuplicateKey | Unique index or shard key value already exists |
| 61 ShardKeyNotFound | The document lacks the shard (partition) key |
| 66 ImmutableField | Updating _id or the shard key |
| 2 BadValue | Sorting on a field without a matching (composite) index; or a multi-document transaction past 5 seconds |
| 67 CannotCreateIndex | Over 500 single-field indexes, or 8 fields in a compound index |
| 112 WriteConflict | Conflicting transactions: retry |
| 26 NamespaceNotFound | Database or collection name doesn't match |
| Socket / endOfStream errors | Idle pooled connections are closed after about 4 minutes: set maxIdleTimeMS=120000 (Node.js: or socketTimeoutMS with keep-alive) |
| Old drivers can't find the account | Append appName=@<account>@ to the connection string |
Cosmos DB for Table
Has its own native data-plane roles, like NoSQL and distinct from Azure RBAC: Built-in Data Reader (…0001: readMetadata, entity read) and Built-in Data Contributor (…0002: tables/*, tables/containers/entities/*); readMetadata must always be allowed for SDK clients, and notDataActions isn't supported. Table storage in a storage account is a different service: reference/storage/tables.md.