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
mongodumpto back up your database, move the backup files out of the defaultdumpfolder. Otherwise, existing files in the folder are overwritten. -
Run the
mongodumpandmongorestorecommands 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
-
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.
-
-
Set a password for the ApsaraDB for MongoDB instance. Set a password.
-
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
-
Log on to the Azure portal.
-
In the left-side navigation pane, click Azure Cosmos DB.
-
On the Azure Cosmos DB page, click the account to migrate.
-
On the account details page, click Connection String.
-
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.NoteRead-only permissions are sufficient for this migration.
-
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 --sslAllowInvalidCertificatesNoteReplace
<HOST>,<USERNAME>, and<PRIMARY PASSWORD>with values from Azure connection information.Wait for the backup to complete. The data is saved to the
dumpfolder in the current directory. -
Obtain the primary node endpoint of the ApsaraDB for MongoDB instance. instance connection overview.
-
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> dumpNote-
<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.