Use mongodump and mongorestore to perform a full offline migration from a MongoDB Atlas database to an ApsaraDB for MongoDB instance. An on-premises server or an Elastic Compute Service (ECS) instance serves as the intermediary and is no longer needed after migration.
Prerequisites
Before you begin, make sure that you have:
An ApsaraDB for MongoDB instance (replica set or sharded cluster). For more information, see Create a replica set instance or Create a sharded cluster instance
Storage capacity on the ApsaraDB for MongoDB instance greater than the MongoDB Atlas database size
The root user password set on the ApsaraDB for MongoDB instance. For more information, see Reset the password of an account for an ApsaraDB for MongoDB instance
MongoDB Database Tools (mongodump and mongorestore) installed on the intermediary server. The tool version must match the MongoDB Atlas database version. For more information, see Install MongoDB
Enough free disk space on the intermediary server to store the dump files (more than the source database size)
The public IP address of the intermediary server added to the ApsaraDB for MongoDB instance whitelist. For more information, see Configure a whitelist for an ApsaraDB for MongoDB instance
(Sharded cluster only) Sharding configured on the destination instance to maximize shard performance. For more information, see Configure sharding to maximize the performance of shards
Required permissions
| Database | Required permission |
|---|---|
| Source MongoDB Atlas database | Read |
| Destination ApsaraDB for MongoDB instance | Read and write |
Usage notes
This is a full data migration. Stop all writes to the source database before migration to keep data consistent.
If the source MongoDB Atlas database and the destination ApsaraDB for MongoDB instance use different MongoDB versions or storage engines, verify compatibility first. For more information, see MongoDB versions and storage engines.
Running
mongodumpoverwrites any existing files in thedumpfolder. Move previous backup files to a different directory before running the command.Run mongodump and mongorestore on the server command line. Do not run them inside the MongoDB shell (mongosh).
Step 1: Export data from MongoDB Atlas
Log on to the MongoDB Atlas console.
Add the public IP address of the intermediary server to the IP access list of the MongoDB Atlas database.

On the Clusters page, click the name of the target cluster.

Click the Command Line Tools tab, then click COPY next to the mongodump command to copy the connection string.

On the intermediary server, paste the copied command and replace the placeholders:
Replace
<PASSWORD>with the database user password.Replace
<DATABASE>with the name of the database to export.
Run the command and wait for the export to finish.
Step 2: Import data to ApsaraDB for MongoDB
Log on to the ApsaraDB for MongoDB console and get the public endpoint of the destination instance: > Note: Apply for a public endpoint first if one has not been allocated. For more information, see Apply for a public endpoint.
Replica set instance: Get the public endpoint of the primary node. For more information, see Overview of replica set instance connections.
Sharded cluster instance: Get the public endpoint of a mongos. For more information, see Overview of sharded cluster instance connections.
Run the following mongorestore command on the intermediary server: > Note: ApsaraDB for MongoDB uses port 3717 by default, which differs from the standard MongoDB port 27017.
Parameter Description <mongodb_host>Public endpoint of the primary node (replica set) or a mongos (sharded cluster) of the ApsaraDB for MongoDB instance <username>Account used to log on to the ApsaraDB for MongoDB instance <database>Name of the database to restore. If the dump contains multiple databases, run this command once for each database <database_backupfile_directory>Path to the backup files for the database mongorestore --host <mongodb_host>:3717 --authenticationDatabase admin -u <username> -d <database> <database_backupfile_directory>When
Enter password:appears, type the password of the ApsaraDB for MongoDB account and press Enter.
Examples
Restore the mongodbtest database:
mongorestore --host dds-bp**********-pub.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u test -d mongodbtest /dump/mongodbtestRestore the test123 database:
mongorestore --host dds-bp**********-pub.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u test -d test123 /dump/test123Verify the migration
After mongorestore finishes, verify that data was migrated successfully:
Connect to the ApsaraDB for MongoDB instance by using mongosh or the DMS console.
Run the following command to list all databases and confirm the migrated databases exist:
show dbsSwitch to a migrated database and check the document count:
use <database> db.stats()Compare the document counts against the source MongoDB Atlas database to confirm all data was transferred.