All Products
Search
Document Center

ApsaraDB for MongoDB:Migrate a self-managed database to a standalone instance

Last Updated:Jul 17, 2026

Migrate a self-managed MongoDB database from an on-premises server or an ECS instance to an ApsaraDB for MongoDB standalone instance by using mongodump and mongorestore.

For zero-downtime migrations, use Data Transmission Service (DTS) instead. For more information, see Full migration from ApsaraDB for MongoDB (standalone architecture) to ApsaraDB for MongoDB (all architectures).

For other migration or synchronization scenarios, see Data migration and synchronization.

Prerequisites

  • The versions of the mongodump and mongorestore tools must match the version of your self-managed MongoDB database. For installation instructions, see the official Install MongoDB documentation.

    Note

    Alternatively, you can run the mongodump and mongorestore commands on the server that hosts your self-managed database without installing them separately.

  • Your self-managed MongoDB database must be version 3.0 or later.

    Note

    For information about supported storage engines, see Versions and storage engines. If you are migrating across different versions or storage engines, verify compatibility before you start.

  • The destination standalone instance must have sufficient storage capacity for the self-managed database. If the storage capacity is insufficient, you can increase it. For more information, see Modify instance configuration.

Usage notes

  • This is a full data migration. To ensure data consistency, stop all related services and write operations on your self-managed database before you start.

  • If you have previously run mongodump, move the existing backup files out of the dump folder before you start. Otherwise, the existing backup files will be overwritten.

  • Run mongodump and mongorestore on the server that hosts your self-managed MongoDB database, not from within the mongo shell.

Step 1: Back up the self-managed database

  1. On the server that hosts your self-managed database, run the following command to back up all databases.

    mongodump --host <mongodb_host> --port <port>  -u <username>  --authenticationDatabase  <database>
    Note
    • <mongodb_host>: The server address of your self-managed MongoDB database. You can use 127.0.0.1 if you are running the command on the database server.

    • <port>: The port number of the database service. The default value is 27017.

    • <username>: The account for the self-managed database, such as test.

    • <database>: The authentication database to which the user account belongs.

    Example:

    mongodump --host 127.0.0.1 --port 27017 -u test --authenticationDatabase admin
  2. When the CLI prompts Enter password:, enter the database account password and press Enter to begin the backup.

    Note

    Password characters are hidden when you enter them.

After the backup is complete, the data from your self-managed database is saved to the dump folder in the current directory.

Step 2: Migrate data to Alibaba Cloud

  1. Obtain the primary node endpoint of the ApsaraDB for MongoDB instance.

    1. Log on to the ApsaraDB for MongoDB console.

    2. In the upper-left corner of the page, select the region where the instance is located.

    3. In the left-side navigation pane, click Replica Set Instances.

    4. Find the target instance and click the instance ID.

    5. In the left-side navigation pane, click Database Connections to view connection details.

      On the connection information page, the VPC and public connection sections display the endpoint for the primary node (for example, dds-<instanceID>.mongodb.rds.aliyuncs.com:3717, where public endpoints include the -pub suffix) and a ConnectionStringURI (for example, mongodb://root:****@<endpoint>/admin). Use the primary node endpoint for the migration.

      Table 1. Connection endpoints

      Endpoint type

      Description

      Scenario

      VPC endpoint

      An isolated network environment that provides higher security and performance than the classic network.

      Use this when your self-managed MongoDB database is on an ECS instance in the same region and VPC as the ApsaraDB for MongoDB instance.

      Note

      The ECS instance and the ApsaraDB for MongoDB instance must be in the same region and VPC.

      public endpoint

      Not enabled by default. You must apply for one before use. For more information, see Apply for a public endpoint.

      Use this when your self-managed MongoDB database is on an on-premises server.

  2. Add the IP address of your self-managed database's server to the whitelist of the ApsaraDB for MongoDB instance. For more information, see Configure a whitelist.

    Note
    • If you connect to the ApsaraDB for MongoDB instance over a VPC, add the private IP address of the ECS instance that hosts your self-managed database to the whitelist.

    • If you connect to the ApsaraDB for MongoDB instance using a public endpoint, add the public IP address of the on-premises server that hosts your self-managed database to the whitelist.

  3. On the server that hosts your self-managed database, run the following command to restore the data to the ApsaraDB for MongoDB instance.

    mongorestore --host <Primary_host>  -u <username> --authenticationDatabase <database> <Backup directory>
    Note
    • <Primary_host>: The primary node endpoint for your ApsaraDB for MongoDB instance.

    • <username>: The database account for the ApsaraDB for MongoDB instance. The initial account is root.

    • <database>: The authentication database. If you use the root account, this database is admin.

    • <Backup directory>: The directory where the backup files are stored. The default directory is dump.

    Example:

    The database account is test, and the authentication database is admin.

    mongorestore --host dds-bp19f409d7512****-pub.mongodb.rds.aliyuncs.com:3717 -u test --authenticationDatabase admin dump
  4. When the CLI prompts Enter password:, enter the password for the ApsaraDB for MongoDB database account and press Enter. The data restoration process starts.

    Note
    • Password characters are hidden when you enter them.

    • If you have forgotten the password for the root account, you can reset it. For more information, see Reset a password.

After the migration is complete, switch your services to the ApsaraDB for MongoDB instance when ready.

Next steps

After the migration, connect to the ApsaraDB for MongoDB instance to manage databases and accounts.