All Products
Search
Document Center

ApsaraDB for MongoDB:Migrate Azure Cosmos DB API for MongoDB to Alibaba Cloud

Last Updated:Jun 02, 2026

Migrate data from Azure Cosmos DB API for MongoDB to ApsaraDB for MongoDB by using the native mongodump and mongorestore tools.

Precautions

  • This is a full migration. Stop all write operations to the source database before you start.

  • If you previously used mongodump to back up your database, move the backup files out of the default dump folder. Otherwise, existing files in the folder are overwritten.

  • Run the mongodump and mongorestore commands on the server where MongoDB is installed, not in the mongo shell.

Required permissions

Instance type

Account permission

Azure Cosmos DB

read

Destination MongoDB instance

readWrite

Prerequisites

  1. Create an ApsaraDB for MongoDB instance. Create an instance.

    Note
    • The destination instance must have more storage than the source Azure Cosmos DB data.

    • Select MongoDB version 4.0 or later.

  2. Set a password for the ApsaraDB for MongoDB instance. Set a password.

  3. Install MongoDB on a server. Install MongoDB.

    Note
    • Install MongoDB 3.0 or later.

    • This server is a temporary host. You can decommission it after migration.

    • The backup directory partition must have more available disk space than the source Azure Cosmos DB data.

    The following steps use a Linux server as an example.

Procedure

  1. Log on to the Azure portal.

  2. In the left-side navigation pane, click Azure Cosmos DB.

  3. On the Azure Cosmos DB page, click the account to migrate.

  4. On the account details page, click Connection String.

  5. Click the Read-only Keys tab.

    Figure 1. Azure connection information. Fields include HOST (xxx.documents.azure.cn), PORT (10255), USERNAME, PRIMARY PASSWORD, SECONDARY PASSWORD, PRIMARY CONNECTION STRING, SECONDARY CONNECTION STRING, and SSL (true). You only need HOST, USERNAME, and PRIMARY PASSWORD.

    Note

    Read-only permissions are sufficient for this migration.

  6. On the Linux server, run the following command to back up the source database.

    mongodump --host <HOST>:10255 --authenticationDatabase admin -u <USERNAME> -p <PRIMARY PASSWORD> --ssl --sslAllowInvalidCertificates
    Note

    Replace <HOST>, <USERNAME>, and <PRIMARY PASSWORD> with values from Azure connection information.

    Wait for the backup to complete. The data is saved to the dump folder in the current directory.

  7. Obtain the primary node endpoint of the ApsaraDB for MongoDB instance. instance connection overview.

  8. On the Linux server, run the following command to restore data to the ApsaraDB for MongoDB instance.

     mongorestore --host <mongodb_host>:3717 --authenticationDatabase admin -u <username> -p <password> dump
    Note
    • <mongodb_host>: the primary node endpoint of the destination instance.

    • <username>: the database username of the destination instance.

    • <password>: the database password of the destination instance.

Wait for the restore to complete.