MongoDB → Azure Cosmos DB for MongoDB
Step-by-step procedure for migrating a MongoDB 4.4+ database (Atlas or on-premises) to Azure Cosmos DB for MongoDB API using Endrias Bridge, including replica set prerequisites, partition key planning, and post-migration index recreation.
Overview & Scope
This SOP covers a full copy (all documents) from a MongoDB 4.4+ source into an Azure Cosmos DB for MongoDB API target using the Endrias Bridge GUI. Because both are document databases, no schema translation occurs — documents are copied verbatim. Containers (collections) and their partition keys must be created in Cosmos DB before migration begins; indexes must be recreated manually after migration.
Prerequisites — Source (MongoDB)
MongoDB must be running in replica set mode. Standalone instances have no oplog and cannot use Change Data Capture (CDC) mode. For full-copy mode, standalone instances are supported but CDC will be unavailable.
// Verify replica set status — must show PRIMARY + at least one SECONDARY
rs.status()
// Set oplog retention to 720 hours (30 days) to protect against migration gaps
db.adminCommand({ setParameter: 1, oplogMinRetentionHours: 720 })
// Source connection URI (generic placeholder)
// mongodb://MigrationUser:password@mongo-source-server:27017/EndriasBridge?authSource=admin
// Grant migration user read access on source DB + clusterMonitor for Change Streams
use admin
db.createUser({
user: "MigrationUser",
pwd: "password",
roles: [
{ role: "read", db: "EndriasBridge" },
{ role: "clusterMonitor", db: "admin" }
]
})
| Requirement | Verify |
|---|---|
MongoDB 4.4+ running in replica set mode (rs.status() shows PRIMARY) | rs.status() |
| At least one SECONDARY confirmed in replica set (for Change Streams / CDC) | rs.status() |
Oplog retention set to 720 hours: oplogMinRetentionHours: 720 | Run command |
MigrationUser has read role on EndriasBridge + clusterMonitor on admin | Create user |
| TCP port 27017 open from migration host to MongoDB server | Network check |
rs.initiate() in the
mongosh shell. This does not require a data reload.Prerequisites — Target (Cosmos DB for MongoDB)
Cosmos DB containers require a partition key that cannot be changed after creation. Plan partition keys carefully before creating containers.
// Target connection URI (generic placeholder)
// mongodb://cosmos-account.mongo.cosmos.azure.com:10255/EndriasBridgeTarget
// ?ssl=true&replicaSet=globaldb&retrywrites=false
// Recommended: set throughput to 10,000 RU/s (autoscale) during migration
// Scale down to steady-state (400–2,000 RU/s) after migration completes
| Requirement | Verify |
|---|---|
| Azure Cosmos DB account created with API = Azure Cosmos DB for MongoDB (version 4.0+) | Azure Portal |
Database EndriasBridgeTarget created in Cosmos DB portal (Data Explorer) | Create DB |
| All containers (collections) created with correct partition key before migration — cannot change after creation | Create containers |
| Throughput set to 10,000 RU/s (autoscale) on each container during migration period | Set RU/s |
| Unique indexes created on target containers before data load (Cosmos DB enforces at insert time) | Create indexes |
TCP port 10255 open from migration host to Cosmos DB account (cosmos-account.mongo.cosmos.azure.com) | Network check |
userId, tenantId).
You cannot change the partition key after container creation without recreating
the container and reloading all data.Configure Connections
Open Endrias Bridge and navigate to Migration Projects. Create a new project and fill in both connection blocks as shown:
SOURCE DATABASE
TARGET DATABASE
Run Assessment
Switch to the Assessment tab and click Run Assessment. Endrias Bridge will connect to the MongoDB source, enumerate all collections with document counts and index definitions, and report any compatibility notes for the Cosmos DB target.
SOURCE COLLECTIONS
users 28,400 docs
orders 142,800 docs
products 9,100 docs
events 440,200 docs
auditlog 88,000 docs
COMPATIBILITY NOTES
• 5 non-_id indexes found — must be recreated post-migration
• No documents exceed 16 MB limit
• No Atlas Vector Search indexes detected
• Partition key not yet configured on target — required before migration
Select Collections
Return to Migration Projects. Click Load Collections from Source. All 5 collections are selected by default. Deselect any collections you want to skip.
_id, which
may not be optimal for your workload.Start Migration & Monitor
Click Start Migration. The migration log updates live as each collection's documents are bulk-inserted. Monitor for RU throttling (error 16500) and increase RU/s if needed.
Verify & Export Report
- Click Verify Document Counts — compares source vs. target document counts per collection and logs mismatches.
- Run manual count validation:
// On source (mongosh) db.users.countDocuments() // On Cosmos DB target (mongosh) db.users.count() - Test a sample of queries against the Cosmos DB target to confirm document shape and partition key distribution.
- Click Export Report (enabled once migration finishes) to save an HTML summary of collections migrated, document counts, and any warnings.
Post-Migration Tasks
Complete the following tasks after verifying document counts:
| Post-Migration Task | Priority |
|---|---|
Recreate all non-_id indexes manually in Azure Portal → Data Explorer | Required |
| Scale down RU/s to steady-state (typically 400–2,000 RU/s per container) | Required |
Validate document counts: db.collection.countDocuments() on source vs db.collection.count() on Cosmos DB | Required |
| Test partition key distribution — query Azure Portal Metrics for hot partitions | Recommended |
Run aggregation pipeline tests ($lookup, $group) and compare performance vs. source | Recommended |
| Verify transaction support: Cosmos DB for MongoDB API 4.0+ supports multi-document transactions | If applicable |
| Review Atlas Vector Search usage — not available on Cosmos DB for MongoDB API (blocking if used) | If applicable |
_id index exists on Cosmos DB containers after migration.
All compound, unique, and text indexes from the source must be recreated manually
via Azure Portal → Data Explorer or via db.collection.createIndex()
in mongosh.Known Issues
| Issue | Detail | Action Required |
|---|---|---|
| Partition key is permanent | Cannot be changed after container creation. Must be a high-cardinality field that most queries filter by. Changing requires full container recreation. | Plan carefully before creating containers |
| 16 MB document limit | Both MongoDB and Cosmos DB enforce a 16 MB per-document limit. Documents exceeding the limit are logged as WARNING and skipped. | Identify and split oversized documents pre-migration |
| Change Streams require replica set | Standalone MongoDB instances have no oplog. Convert to single-node replica set (rs.initiate()) before CDC mode. |
Run rs.initiate() on standalone instances |
| Cosmos DB Change Feed retention | Permanent — no time limit. This is a key advantage over DynamoDB Streams (24h hard limit). | No action — advantage over source |
| Indexes not migrated | Only the _id index exists post-migration. All other indexes must be manually recreated in Azure Portal or via mongosh. |
Recreate all non-_id indexes post-migration |
| Atlas Vector Search | Not available on Cosmos DB for MongoDB API. This is a blocking constraint if the application uses Atlas Vector Search queries. | Assess before committing to Cosmos DB target |
| Transactions | Supported on Cosmos DB for MongoDB API 4.0+. Verify your Cosmos DB account API version before migration. | Confirm API version 4.0+ in Azure Portal |
| $lookup (joins) performance | Supported but with different performance characteristics than MongoDB. Cross-partition lookups are especially expensive. | Test aggregation pipelines post-migration |
| RU throttling (error 16500) | TooManyRequests — Cosmos DB is rate-limiting writes. Endrias Bridge retries automatically, but migration throughput will degrade. |
Increase RU/s on container during migration |
Collection & Object Mapping (MongoDB → Cosmos DB)
| MongoDB Object | Cosmos DB Equivalent | Notes |
|---|---|---|
| Database | Database | Created in Cosmos DB portal |
| Collection | Container | Partition key required — choose before creation |
| Document | Item | 16 MB limit; _id preserved |
| ObjectId | ObjectId | Preserved as-is |
Index (non-_id) | Index | Must be manually recreated post-migration |
| Unique index | Unique index | Create before data load |
| Compound index | Compound index | Recreate post-migration |
| Text index | Text index | Limited support — test queries post-migration |
| Change Stream | Change Feed | Change Feed is permanent; no retention time limit |
| Replica Set | N/A (managed) | Cosmos DB is a fully managed service |
| Shard key | Partition key | Equivalent concept — permanent after container creation |