Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
For applications that need an Azure-hosted MongoDB-compatible database service, Azure DocumentDB (with MongoDB compatibility) is a fully managed, MongoDB-compatible database on Azure. Most applications connect with their existing MongoDB drivers, tools, and code without changes. Azure DocumentDB supports 99.03% of MongoDB operators, measured as described in MongoDB compatibility. Azure DocumentDB has just two components - compute and storage - and includes backups for up to 35 days on production SKUs (M30 and above).
A VS Code integration migration tool, also available as a standalone tool if needed, supports online and offline migrations.
For details, see What is Azure DocumentDB? and Azure DocumentDB pricing explained.
Migrate from MongoDB Atlas to Azure DocumentDB (with MongoDB compatibility)
This article covers what's specific to migrating from MongoDB Atlas to Azure DocumentDB (with MongoDB compatibility): preparing the source cluster, setting up network access, planning for capabilities your application might use, and cutting over. The source can run on any cloud provider. You can migrate online with minimal downtime by using free tools.
For the general migration process (assess, prepare, refine, migrate, validate, and cut over) and the full list of tools, see Migration options. This article doesn't repeat those steps.
Choose a migration tool
| Tool | Migration type | Best for |
|---|---|---|
| Azure DocumentDB migration extension for Visual Studio Code | Online or offline | Most migrations. Includes the compatibility assessment and lets you choose databases and collections. |
| Azure Database Migration Service | Online or offline | Migrations managed from the Azure portal that keep running after you close the browser. |
| Native MongoDB tools (mongodump and mongorestore) | Offline only | Small databases, and source clusters that don't support change streams. |
Before you start
Check that your source supports online migration
Online migration copies your data and then replicates ongoing changes by reading the source's change streams. Before you plan an online migration, confirm that:
- Change streams are available on your source cluster tier. If your source tier doesn't support change streams, use an offline migration with the native MongoDB tools.
- The oplog is large enough to cover the whole migration window, including the initial copy of large collections. If your source lets you set an oplog size or a minimum oplog window, raise it for the duration of the migration.
- Source writes are steady. Very high write rates during the initial copy lengthen the time needed to catch up.
Create a database user for the migration
Create a dedicated database user on the source cluster for the migration extension or Azure Database Migration Service with the readAnyDatabase and clusterMonitor roles. These roles are also required for the compatibility assessment. Remove the user after cutover.
Get your connection string
Use your source cluster's standard connection string. Both the mongodb+srv:// (SRV) and mongodb:// formats work with the migration tools. URL-encode any special characters, such as @, #, and :, in the password.
Assess compatibility
Run the compatibility assessment in the Azure DocumentDB migration extension for Visual Studio Code against your source cluster. It reports any unsupported features, commands, query syntax, and index types. Resolve the findings before you migrate. See Assess and plan migration readiness.
Set up network access
The migration tool must be able to reach your source cluster.
| Where the migration tool runs | How to allow access |
|---|---|
| Azure Database Migration Service or another Azure-hosted tool | Add the tool's outbound public IP addresses to your source cluster's IP access list, or connect privately through a private endpoint. |
| The migration extension on your workstation | Add your workstation's public IP address to the source cluster's IP access list. |
| A virtual machine in Azure | Add the VM's public IP address to the IP access list, or connect privately if your source cluster runs on Azure and supports private connectivity. |
To keep latency low during migration:
- Run the migration tool in the same region as your source cluster, or as close to it as possible.
- Create your Azure DocumentDB cluster in the region where your application will run after cutover.
- If your source runs on another cloud provider, the source provider might charge for data that leaves its network during migration. Plan the timing of large initial copies with that in mind.
Plan for capabilities your application uses
Some applications rely on capabilities that a managed service provides outside the core MongoDB query language. If your application uses any of these capabilities, plan the Azure DocumentDB equivalent before you migrate.
| If your application uses... | Plan to use in Azure DocumentDB |
|---|---|
Full-text search indexes and queries using the $search aggregation stage |
Azure DocumentDB text search. Recreate the indexes and rewrite $search queries to use $text. |
Vector search indexes and queries using the $vectorSearch aggregation stage |
Azure DocumentDB vector search. Recreate vector indexes (DiskANN, HNSW, or IVF) and update query syntax. |
| Database triggers that run code when data changes | Azure Functions that read Azure DocumentDB change streams. |
| Scheduled or serverless functions that query the database | Azure Functions or Azure Container Apps jobs that connect with a MongoDB driver. |
| Embedded charts and dashboards | Power BI connected to Azure DocumentDB. |
| Archiving cold data to object storage, or querying across a database and object storage | Azure DocumentDB change streams with Azure Data Factory or Spark to land data in Azure Storage or Microsoft Fabric. |
| Device or mobile data sync | No built-in equivalent. Sync through your application tier. |
Custom server-side logic, such as $function or $where |
Check the compatibility assessment results and move the logic into your application if needed. |
Your existing indexes, other than search and vector search indexes, migrate with your data. Review your indexing strategy after migration.
Migrate
- Create an Azure DocumentDB cluster sized to your workload. For a first trial, you can use a free tier cluster.
- Run a trial migration on a representative subset of your data to measure throughput and confirm your cluster tier, storage, and shard count.
- Run the production migration in online mode with the migration extension or Azure Database Migration Service.
- Monitor progress until the target catches up with the source and replication lag is consistently low.
For step-by-step instructions, see the tool's how-to article linked in Choose a migration tool.
Cut over
- Validate the data. Compare document counts per collection, run sample-based checks on document contents, and confirm that indexes exist on the target.
- Move read traffic first. Point read-only parts of your application at Azure DocumentDB and confirm query results and performance.
- Stop writes to the source. Put your application into a short maintenance window, or stop the write path.
- Let the last changes replicate, then stop the migration job.
- Move write traffic. Update your application's connection string to your Azure DocumentDB cluster.
- Monitor closely with Azure Monitor metrics during the first hours after cutover.
Keep a fallback
Keep your source cluster running, unchanged, until you're confident in the migration. If you need to roll back before new writes reach Azure DocumentDB, switch your connection string back to the source. After writes start on Azure DocumentDB, rolling back requires migrating those new writes back to the source. Decide your rollback point in advance.
After cutover, decommission the source cluster and delete the migration database user.
Get help
- Self-service: Migration options and best practices.
- Customer story: (How a large enterprise migrated 47TB and 7,000+ collections to Azure DocumentDB in under 48 hours)