Limited Time Offer: 40% off
Back to Blog

Cosmos DB vs MongoDB: RU, vCore, and Atlas Compared

JayJay

Cosmos DB vs MongoDB is now a three-way choice. MongoDB is the database itself, self-hosted or on MongoDB Atlas, which runs on Azure as well as AWS and Google Cloud. Azure Cosmos DB for MongoDB (RU) is Cosmos DB's own engine with a MongoDB-compatible API, billed in request units. Azure DocumentDB is what Microsoft called Azure Cosmos DB for MongoDB (vCore) until November 2025. It runs the open-source DocumentDB engine on PostgreSQL, on dedicated clusters.

If you are moving an existing MongoDB application to Azure, choose MongoDB Atlas on Azure for full compatibility or Azure DocumentDB for an Azure-native service with broad compatibility. Choose Cosmos DB (RU) only when you want its specific strengths (multi-region writes, per-request elastic throughput, and serverless billing) and your queries are simple enough to live within its MongoDB feature set.

MongoDB / AtlasCosmos DB for MongoDB (RU)Azure DocumentDB (formerly vCore)
EngineMongoDB serverCosmos DB engineOpen-source DocumentDB on PostgreSQL
BillingCluster tier per hour (Atlas)Request units: provisioned, autoscale, or serverlessCompute tier plus storage
MongoDB APINative, current releasesServer versions 3.6 to 7.0, with many gapsBroad wire protocol support
Multi-document transactionsAcross collections and shardsSingle unsharded collection, fixed 5-second timeoutAcross collections
$lookup with let and pipelineYesNoYes (tested on the open-source engine)
Text indexesYesNoYes (tested on the open-source engine)
Default document size limit16 MB2 MB, 16 MB opt-in16 MB (open-source engine)
Global distributionMulti-region clusters, global clustersTurn-key multi-region, multi-region writesRegional, with geo-replicas
Where it runsAny cloud or your own serversAzure onlyAzure, or self-host the open-source engine

The MongoDB examples below ran on MongoDB 8.3 in Docker, and the DocumentDB checks ran on the open-source documentdb-local image. Cosmos DB behaviour comes from Microsoft's documentation.

Cosmos DB for MongoDB: which one?

Microsoft's naming has changed, and older blog posts use the old names.

  • Azure Cosmos DB is Microsoft's globally distributed database service. Its native API is Azure Cosmos DB for NoSQL, and it also offers compatibility APIs for MongoDB, Cassandra, Gremlin, and Table.
  • Azure Cosmos DB for MongoDB (RU) is the MongoDB-compatible API on that engine. When people say "Cosmos DB for MongoDB" today, this is it.
  • Azure Cosmos DB for MongoDB (vCore) was a separate product built on PostgreSQL. On November 18, 2025, Microsoft renamed it Azure DocumentDB and made it its own service, aligned with the open-source DocumentDB project under the Linux Foundation.

Microsoft's own RU documentation now opens with a pointer: if you are "looking to migrate an existing MongoDB application or use MongoDB Query Language (MQL) features", consider Azure DocumentDB. That tells you where Microsoft expects MongoDB migrations to land.

How request units work

Cosmos DB normalises the cost of every operation into request units (RUs). Microsoft's reference point is that reading one item of about 1 KB by its ID and partition key costs one RU. Larger items, more indexed properties, and more complex queries cost more. Strong and bounded staleness consistency cost roughly twice as many RUs for reads as the relaxed levels.

You pay for RUs in one of three modes:

  • Provisioned throughput: you set RU/s on a database or collection in increments of 100 and are billed hourly for what you provision.
  • Autoscale: throughput scales between a floor and a maximum you set, based on usage.
  • Serverless: no provisioned throughput, and you are billed for the RUs you consume.

Provisioned RUs apply in every region of the account. Provision R RU/s on an account with N regions, and you pay for R × N.

When a MongoDB API workload goes over its provisioned RU/s, requests are rate limited and appear as 16500 errors. Enabling Server Side Retry makes Cosmos DB retry those requests for you, up to a 60-second timeout, after which the client gets an ExceededTimeLimit error (code 50).

To see what a query costs, Cosmos DB adds a custom command:

JAVASCRIPT
db.runCommand({ getLastRequestStatistics: 1 })

The result includes a RequestCharge field for the previous operation. It is a Cosmos DB extension, so MongoDB itself rejects it:

MongoServerError: no such command: 'getLastRequestStatistics'

The RU model is the main reason to choose Cosmos DB. You get fine-grained, SLA-backed throughput and instant scaling. The cost is that every query has a price you need to watch, and an unindexed or cross-partition query can consume throughput quickly.

Compatibility: what Cosmos DB for MongoDB (RU) does not support

Microsoft publishes feature pages for RU server versions 3.6, 4.0, 4.2, 5.0, 6.0, and 7.0. The version number sets the wire protocol level. It does not mean the engine behaves like that MongoDB release. The 7.0 page lists the same key limits as older versions.

Transactions

Cosmos DB for MongoDB (RU) supports multi-document transactions only "within a single nonsharded collection." Transactions across collections, or in sharded collections, are not supported, and the transaction timeout is a fixed 5 seconds.

On MongoDB, this transaction inserts an order and decrements stock in a second collection:

JAVASCRIPT
const session = db.getMongo().startSession();
const s = session.getDatabase("shop");

session.startTransaction();
s.orders.insertOne({ _id: 4, customer: "grace", status: "pending", total: 36.00 });
s.inventory.updateOne({ _id: "MS-02" }, { $inc: { stock: -2 } });
session.commitTransaction();

db.inventory.findOne({ _id: "MS-02" });
{ _id: 'MS-02', stock: 3 }

The same script committed on the open-source DocumentDB engine. On Cosmos DB (RU), it crosses two collections, so you would need to redesign it, for example by embedding stock updates in one collection or using another pattern such as an outbox.

$lookup with sub-pipelines

Cosmos DB (RU) supports only the basic form of $lookup, with localField and foreignField. Using let and pipeline returns an error that "let isn't supported." This query ran on MongoDB and returned the same output on DocumentDB:

JAVASCRIPT
db.orders.aggregate([
  { $lookup: {
      from: "inventory",
      let: { sku: "$sku" },
      pipeline: [
        { $match: { $expr: { $eq: ["$_id", "$$sku"] } } },
        { $project: { stock: 1 } }
      ],
      as: "stock"
  } },
  { $match: { _id: 5 } }
])
[
  {
    _id: 5,
    sku: 'MS-02',
    status: 'pending',
    stock: [ { _id: 'MS-02', stock: 3 } ]
  }
]

Text search

Text indexes and the $text operator are not supported on Cosmos DB (RU). Microsoft suggests $regex instead. On MongoDB:

JAVASCRIPT
db.articles.createIndex({ title: "text" });
db.articles.find({ $text: { $search: "index" } }, { _id: 0, title: 1 });
[
  { title: 'Tuning MongoDB indexes' },
  { title: 'Index design for time series' }
]

The stemmed match on "indexes" is what $regex will not give you.

Other differences worth checking

From Microsoft's feature pages for RU accounts:

  • Unsupported: $where, mapReduce, $graphLookup, $bucket, $jsonSchema, hashed indexes, sparse indexes, and renameCollection.
  • Partial indexes are supported only as unique indexes.
  • Write concern is ignored. Microsoft states that "all writes are automatically Quorum by default" and that client write concerns are ignored.
  • Users and roles from MongoDB are not supported. Access uses Azure role-based access control and account keys.
  • Documents are limited to 2 MB unless you enable 16 MB support, which applies only to collections created after enabling it and cannot be turned off.
  • Sorting on multiple fields needs a compound index, and findOneAndUpdate supports sorting on one field only.
  • Retryable writes are a feature flag. With it on, updates and deletes on sharded collections must include the shard key.

Most CRUD code and many aggregation pipelines work. Applications that use transactions across collections, rich $lookup, or text search need changes.

DB Pro

Work With Your Databases Like A Pro

Query, explore, and manage your databases with a beautiful desktop app and built-in AI.

Download Now
DB Pro Dashboard

Azure DocumentDB (formerly vCore)

Azure DocumentDB is the better Azure fit for most MongoDB applications. It runs the MIT-licensed DocumentDB engine, bills for compute tier and storage like a traditional cluster, and supports transactions across collections, full $lookup, text indexes, and vector search. Microsoft describes it as "99.03% MongoDB-compatible", its own figure.

The open-source engine it builds on is not complete. In my local test, capped collections, time series collections, $where, mapReduce, and change streams returned CommandNotSupported or BadValue errors. Check Microsoft's compatibility pages for the managed service, since it may differ from the build I ran. Our DocumentDB vs MongoDB comparison has the full test output.

Microsoft also offers an online and offline migration path from Cosmos DB for MongoDB (RU) to Azure DocumentDB, generally available since November 2025. If you are on RU today and hitting the limits above, that is the path Microsoft is steering customers toward.

Scaling and global distribution

Cosmos DB's strongest feature is global distribution. You add Azure regions to an account, data replicates automatically, and multi-region writes let every region accept writes. Five consistency levels (strong, bounded staleness, session, consistent prefix, and eventual) let you trade latency against freshness. Microsoft offers a 99.999% availability SLA for multi-region accounts. Partitioning is automatic, and there are no sharding commands to run.

MongoDB scales with replica sets for availability and sharding for write capacity. Atlas supports multi-region and multi-cloud clusters, and global clusters that pin data to zones for locality. Writes for a given shard go to one primary, so active-active writes to the same data from several regions are not how MongoDB works. For most applications, one primary region with remote read replicas is enough.

Azure DocumentDB scales vertically by cluster tier and horizontally by sharding, with geo-replicas for cross-region reads and disaster recovery. It does not offer Cosmos DB's turn-key multi-region writes.

Pricing models

Compare the billing models before comparing numbers.

  • Cosmos DB (RU) charges for throughput (provisioned RU/s, autoscale maximum, or consumed RUs on serverless) plus storage. Costs track how many and how expensive your operations are, multiplied by region count.
  • Azure DocumentDB charges for cluster compute tier and storage. Costs track cluster size, not per-query work.
  • MongoDB Atlas charges per cluster tier per hour for dedicated clusters, with a Flex tier for small workloads. Self-hosted MongoDB Community has no licence fee.

For steady workloads with heavy aggregations, cluster-based pricing is usually easier to predict. For spiky or low-volume workloads, serverless RUs can cost less. Run your real queries, measure RU charges with getLastRequestStatistics, and model the bill before committing.

When to choose Cosmos DB for MongoDB (RU)

  • You need multi-region writes and low latency in several Azure regions.
  • Traffic is spiky or small, and serverless or autoscale billing fits.
  • Access patterns are mostly point reads and simple queries by partition key.
  • You are building new, so you can design around the limits instead of migrating around them.

If you are building new on Cosmos DB and do not need MongoDB drivers, also look at Cosmos DB for NoSQL, which is the engine's native API.

When to choose Azure DocumentDB

  • You are moving an existing MongoDB application to Azure.
  • Your app uses transactions across collections, $lookup pipelines, or text search.
  • You want predictable, cluster-based pricing and an open-source engine underneath.

When to choose MongoDB or Atlas

  • You need full MongoDB compatibility, including change streams, time series collections, and the newest release features.
  • You want the option to run on more than one cloud or on your own servers.
  • Your team already knows MongoDB operations and tooling. DB Pro's MongoDB desktop client is one option for day-to-day querying.

Verdict: Cosmos DB vs MongoDB

For an existing MongoDB application, Cosmos DB for MongoDB (RU) is usually the wrong target. Its transaction, $lookup, and text search limits mean code changes, and Microsoft itself points MongoDB migrations to Azure DocumentDB. Pick Atlas on Azure for full compatibility, or Azure DocumentDB for an Azure-native managed service.

Cosmos DB earns its place when global distribution and elastic, per-request throughput are the requirements, not MongoDB compatibility. For other options, see the MongoDB alternatives guide, DynamoDB vs MongoDB for the AWS equivalent, and MongoDB vs PostgreSQL.

Keep Reading