Combine full and incremental data migration to move your self-managed MongoDB replica set data to ApsaraDB for MongoDB with zero downtime.
You can also use MongoDB tools to migrate a self-managed database to a replica set instance. Data migration and synchronization covers additional scenarios.
Prerequisites
- The source and destination MongoDB versions must be compatible. Check the Migration solutions overview.
- The destination ApsaraDB for MongoDB instance should have at least 10% more storage than the source database.
Usage notes
- Full data migration consumes resources on both the source and destination, which increases server load and may cause service disruptions. Migrate during off-peak hours if your database handles high traffic or runs on limited hardware.
- Check Versions and storage engines for supported MongoDB configurations. Verify compatibility before migrating across versions or storage engines.
-
The
adminandlocaldatabases cannot be set as the source or destination database. - DTS writes data to the destination concurrently, which may cause the destination to use 5%–10% more storage than the source.
- Ensure no documents in the destination share a primary key (
_idby default) with documents in the source. Duplicate keys may cause data to be overwritten. Delete duplicates in the destination before migration if doing so does not affect your business.
Billing
| Migration type | Task configuration fee | Public traffic fee |
| Full data migration | Free of charge. | You are charged for outbound traffic when migrating from Alibaba Cloud over the public network. Pricing details: Billing overview. |
| Incremental data migration | Charged. Pricing details: Billing overview. |
Migration types
- Full data migration: Migrates all existing data from the selected objects in the source MongoDB database to the destination MongoDB database. Note This includes databases, collections, and indexes.
- Incremental data migration: After the full data migration is complete, DTS synchronizes data changes from the source MongoDB database to the destination. Note
- Synchronizes
CREATEandDELETEoperations for databases, collections, and indexes. - Synchronizes
INSERT,UPDATE, andDELETEoperations for documents.
- Synchronizes
Database account permissions
| Database | Full data migration | Incremental data migration |
| Self-managed MongoDB database | read permission on the databases to be migrated. |
read permission on the databases to be migrated, and on the admin and local databases. |
| ApsaraDB for MongoDB instance | readWrite permission on the destination database. |
readWrite permission on the destination database. |
To create accounts and grant permissions:
- ApsaraDB for MongoDB: Manage MongoDB database users in DMS
- Self-managed MongoDB:
db.createUser()(official MongoDB documentation)
Procedure
- Log on to the DTS console.
- In the left-side navigation pane, click Data Migration.
- At the top of the Migration Tasks page, select the region where your destination ApsaraDB for MongoDB instance is located.
- In the upper-right corner, click Create Data Migration Task.
- Configure the source and destination databases.
Section Parameter Description N/A Task Name DTS auto-generates a task name. Specify a descriptive name for easy identification. Uniqueness is not required. Source database Instance Type Select the source database deployment type. This example uses User-Created Database with Public IP Address. NoteFor other instance types, complete the required Preparations before proceeding.
Instance Region If you select User-Created Database with Public IP Address for Instance Region, you do not need to set this parameter. Note Instance RegionIf a whitelist is configured for your self-managed database, click Get IP Address Segment of DTS to obtain the CIDR blocks of the DTS servers. Add these CIDR blocks to the whitelist of your self-managed database.Database Type Select MongoDB. Hostname or IP Address Enter the self-managed MongoDB database endpoint. In this example, use the public IP address. Port Number Enter the service port of your self-managed MongoDB database. Note In this example, the service port must be accessible over the public network.Database Name Enter the name of the authentication database for this account. Database account Enter the self-managed MongoDB database account with the permissions listed in Required permissions for database accounts. Database password Enter the password for the database account. Note Database PasswordAfter configuring the source database, click Test Connectivity to verify that the provided information is correct. If the test is successful, a Passed message appears. If the test fails, a FailedFailed message appears. Click Diagnose next to the message to identify and correct any errors.Encryption Select Non-encrypted. Note You can select SSL-encrypted only when you migrate data from a MongoDB Atlas database.Destination database Instance Type Select MongoDB Instance. Instance Region Select the region of the destination ApsaraDB for MongoDB instance. MongoDB Instance ID Select the ID of the destination ApsaraDB for MongoDB instance. Database Name Enter the name of the authentication database for this account. Database account Enter the ApsaraDB for MongoDB account with the permissions listed in Required permissions for database accounts. Database password Enter the password for the database account. Note Database PasswordAfter configuring the destination database, click Test Connectivity to verify that the provided information is correct. If the test is successful, a Passed message appears. If the test fails, a FailedFailed message appears. Click Diagnose next to the message to identify and correct any errors. - After completing the configurations, click Authorize Whitelist and Go to Next Step.
If the source or destination database is an Alibaba Cloud database instance, such as RDS MySQL or ApsaraDB for MongoDB, DTS automatically adds the IP addresses of the DTS service in the corresponding region to the whitelist of the Alibaba Cloud database instance. If the source or destination database is a self-managed database on an ECS instance, DTS automatically adds the IP addresses of the DTS service in the corresponding region to the security group rules of the ECS instance. You must also ensure that the self-managed database does not restrict access from the ECS instance. (If the database is deployed as a cluster on multiple ECS instances, you must manually add the IP addresses of the DTS service in the corresponding region to the security group rules of each of the other ECS instances.) If the source or destination database is a self-managed database in an on-premises data center (IDC) or a database from another cloud provider, you must manually add the IP addresses of the DTS service in the corresponding region to allow access from DTS servers. For the IP addresses of the DTS service, see IP address blocks of DTS servers.
WarningAdding public IP addresses of DTS servers may introduce security risks. By using this product, you acknowledge and accept these risks. Implement basic security measures such as strong passwords, restricted ports, API authentication, regular network segment reviews, or private connections through Express Connect, VPN Gateway, or Smart Access Gateway.
- Select the migration types and the objects to be migrated.
Parameter Description Migration type - For an offline migration, select only Full Data Migration.
- For a zero-downtime migration, select both Full Data Migration and Incremental Data Migration.
Note If you do not select Incremental Data Migration, do not write new data to the self-managed MongoDB database during the migration. This ensures data consistency between the source and destination.Migration objects - In the Available list, click the objects you want to migrate, and then click the
icon to move them to the Selected Objects list. Note Theadmin,local, andconfigdatabases cannot be migrated. - You can select databases, collections, or functions as migration objects.
- Object names are preserved after migration by default. To rename objects, use the Object name mapping feature.
Specify whether to rename objects Rename objects in the destination using the Object name mapping feature. Retry duration for unstable source/destination database connections Default: 12 hours (customizable). If DTS reconnects within this period, the task resumes automatically. Otherwise, the task fails. Note The DTS task incurs charges during retries. Set the retry duration based on your business needs and release the DTS instance when no longer needed to avoid unnecessary costs. -
After you complete these settings, click Pre-check and Start in the lower-right corner of the page.
Note-
DTS performs a precheck before the task starts. The task can start only after it passes the precheck.
-
If the precheck fails, click the
icon next to the failed item to view details.-
Fix the issues based on the details, and then run the precheck again.
-
For warnings that do not require a fix, you can select Ignore or Ignore and Rerun Precheck to run the precheck again.
-
-
- After the precheck is successful, click Next.
- On the Confirm Purchase Configuration page, select an Instance Class and select the Data Transmission (Pay-As-You-Go) Terms of Service checkbox.
- Click Buy and Start to start the migration task.
- Full data migration
Do not manually stop the task — incomplete data may result. The task stops automatically when complete.
- Incremental data migration
The task does not stop automatically. Stop it manually.
Note Stop the task during off-peak hours or when you are ready to switch your business to the ApsaraDB for MongoDB instance.- Wait until the task progress changes to Incremental Data Migration and shows Undelayed. Then, stop writing data to the source database for a few minutes. A latency value might appear under the Incremental Data Migration status as the final changes are synchronized.
- After the Incremental Data Migration status returns to Undelayed, manually stop the migration task.
- Full data migration
- Switch your business workloads to the ApsaraDB for MongoDB instance.