All Products
Search
Document Center

ApsaraDB for MongoDB:Migrate data from MongoDB Atlas to ApsaraDB for MongoDB by using mongodump and mongorestore

Last Updated:Feb 27, 2026

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:

Required permissions

DatabaseRequired permission
Source MongoDB Atlas databaseRead
Destination ApsaraDB for MongoDB instanceRead 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 mongodump overwrites any existing files in the dump folder. 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

  1. Log on to the MongoDB Atlas console.

  2. Add the public IP address of the intermediary server to the IP access list of the MongoDB Atlas database. Configure a whitelist for the MongoDB Atlas database

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

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

  5. 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.

  6. Run the command and wait for the export to finish.

Step 2: Import data to ApsaraDB for MongoDB

  1. 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.

  2. 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.

    ParameterDescription
    <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>
  3. 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/mongodbtest

Restore the test123 database:

mongorestore --host dds-bp**********-pub.mongodb.rds.aliyuncs.com:3717 --authenticationDatabase admin -u test -d test123 /dump/test123

Verify the migration

After mongorestore finishes, verify that data was migrated successfully:

  1. Connect to the ApsaraDB for MongoDB instance by using mongosh or the DMS console.

  2. Run the following command to list all databases and confirm the migrated databases exist:

       show dbs
  3. Switch to a migrated database and check the document count:

       use <database>
       db.stats()
  4. Compare the document counts against the source MongoDB Atlas database to confirm all data was transferred.