MongoDB Database Migration
DRS helps you migrate MongoDB databases from other cloud platforms to DDS on the current cloud. With DRS, you can migrate databases online with zero downtime and your services and databases can remain operational during migration.
This section describes how to use DRS to migrate MongoDB databases from another cloud to DDS on the current cloud. Migration scenarios include:
- Migrating MongoDB databases from another cloud to DDS on the current cloud.
- Migrating self-built MongoDB databases from servers on another cloud to DDS on the current cloud.
Diagram
Migration Process
Migration Suggestions (Important)
- Database migration is closely impacted by a wide range of environmental and operational factors. To ensure the migration goes smoothly, you are advised to perform a test run before the actual migration to help you detect and resolve any potential issues in advance. Recommendations on how to minimize any potential impacts on your data base are provided in this section.
- It is strongly recommended that you start your migration task during off-peak hours. A less active database is easier to migrate successfully. If the data is fairly static, there is less likely to be any severe performance impacts during the migration.
Notes on Migration (Important)
Before creating a migration task, read the migration notes carefully.
For details, see the Before You Start section in the Getting Started with Data Replication Service.
Preparing the Migration
- Permissions Table 1 lists the permissions required for the source and destination databases when migrating a MongoDB database from another cloud to DDS on the current cloud.
Table 1 Migration permissions Database
Full Migration Permission
Full+Incremental Migration Permission
Source
- Replica set: The source database user must have the readAnyDatabase permission on the admin database.
- Cluster: The source database user must have the readAnyDatabase permission on the admin database and the read permission on the config database.
- Single node: The source database user must have the readAnyDatabase permission on the admin database.
- To migrate accounts and roles of the source database, the source database user must have the read permission on the system.users and system.roles system tables of the admin database.
- Replica set: The source database user must have the readAnyDatabase permission on the admin database and have the read permission on the local database.
- Single node: The source database user must have the readAnyDatabase permission on the admin database and the read permission on the local database.
- Cluster: The source database user that connects to the mongos node must have the readAnyDatabase permission on the admin database and the read permission on the config database. The source database user that connects to the shard nodes must have the readAnyDatabase permission on the admin database and the read permission on the local database.
- To migrate accounts and roles of the source database, the source database user must have the read permission on the system.users and system.roles system tables of the admin database.
Destination
The destination database user must have the readAnyDatabase permission on the admin database and the readWrite permission on the destination database.
- Source database permissions:
The source MongoDB database user must have all the required permissions listed in Table 1. If the permissions are insufficient, create a user that has all of the permissions on the source database.
Currently, you can use DRS to migrate databases on Alibaba Cloud, Tencent Cloud, and Amazon Web Services.
For example, if you want to migrate an Alibaba Cloud MongoDB database to a DDS database, you can use the initial account of the source database.
- Destination database permissions:
If the destination database is a DDS database, the initial account can be used.
- Network settings
- Source database network settings:
Any source database MongoDB instances will need to be accessible from the Internet.
For example, if you want to migrate an Alibaba Cloud MongoDB database to DDS on the current cloud, you need to apply for a public IP address for your source database. For details, see related documents provided by Alibaba Cloud.
- Source database network settings:
- Security rules
- Source database security group settings:
The replication instance needs to be able to access the source MongoDB instance. That means that the EIP of the replication instance must be on the whitelist of the source MongoDB instance.
For example, if you want to migrate an Alibaba Cloud MongoDB database to a DDS database, you need to set the source database whitelist by referring to related documents provided by Alibaba Cloud. Before setting the network whitelist, you need to obtain the EIP of the replication instance.
- After creating a replication instance on the DRS console, you can find the EIP on the Configure Source and Destination Databases page as shown in Figure 4.
You can also add 0.0.0.0/0 to the source database whitelist to allow any IP address to access the source database but this action may result in security risks.
If you do take this step, then once the migration is complete, you should delete this item from the whitelist or your system will insecure.
- Destination database security group settings:
By default, the destination database and the DRS replication instance are in the same VPC and can communicate with each other. No further configuration is required.
- Source database security group settings:
- Other
You need to export the user information of the MongoDB database first and manually add it to the destination DDS DB instance because the user information will not be migrated.
Migration Procedure
- Create a migration task.
- Log in to the management console and choose to go to the DRS console.
- On the Online Migration Management page, click Create Migration Task.
- On the Create Replication Instance page, configure the task details, recipient, and replication instance and click Next. Figure 5 Replication instance information
Table 2 Task information Parameter
Description
Task Name
Consists of 4 to 64 characters, starts with a letter, and can contain only letters (case-insensitive), digits, hyphens (-), and underscores (_).
Send Notifications
If the function is enabled, DRS will send notifications to the specified recipients based on the mobile numbers and email addresses you provided. If an exception occurs during the migration, the system will send a notification to the specified recipients.
NOTE:Recipients must confirm the subscription on the SMN console within 48 hours of receiving an SMS message or email. Otherwise, they cannot receive notifications from DRS.
Synchronization Delay Threshold
During an incremental migration, a synchronization delay indicates a time difference (in seconds) of synchronization between the source and destination database.
If the synchronization delay exceeds the threshold you specify, DRS will send notifications to the specified recipients. The value ranges from 1 to 3,600. The unit is second.
NOTE:In the early stages of an incremental migration, there is more delay because more data is waiting to be synchronized. In this situation, no notifications will be sent.
Description
Consists of a maximum of 256 characters and cannot contain the following special characters: !=<>'&"
Table 3 Replication instance settings Parameter
Description
Data Flow
To the cloud
Source DB Engine
MongoDB database
Destination DB Engine
DDS
Network Type
Public network
Enabling SSL is recommended. It may slow down the migration by 20% to 30% but it ensures data security.
Destination DB Instance
The DDS DB instance you purchased.
Migration Type
- Full
It migrates all data at one time. If you perform a full migration, you are advised to stop operations on the source database. Otherwise, data generated in the source database during the migration will not be synchronized to the destination database.
- Full+Incremental
An incremental migration can keep data consistency after a full migration is complete.
You can select Full+Incremental to enable the source and destination database services to remain accessible during the migration.
- On the Configure Source and Destination Databases page, wait until the replication instance is created, and then configure the source and destination database details. You are advised to click Test Connection in the Source Database and Destination Database areas to check that both the source and destination databases are connected. Then, select the check box before the agreement and click Next. Figure 6 Source and destination database details
Table 4 Source database information Parameter
Description
IP Address or Domain Name
The IP address or domain name of the source database.
Port
The port of the source database.
Range: 1 - 65535
Database Username
A username for the source database.
Database Password
The password for the source database username.
SSL Connection
To improve data security during a migration on a public network, you are advised to enable SSL to encrypt migration links and upload a CA certificate.
Table 5 Destination database information Parameter
Description
DB Instance Name
The DDS DB instance you have selected during the replication instance creation is displayed by default and cannot be changed.
Database Username
The username for accessing the destination DDS DB instance.
Database Password
The password for the database username.
- On the Set Task page, select a migration type and migration objects. Figure 7 Migration objects
Table 6 Migration types and objects Parameter
Description
Migration Object
Select the objects to be migrated. The objects can be either databases or tables. After the objects are migrated to the destination DB instance, the object names remain the same as those in the source database and cannot be modified.
- On the Check Task page, check the migration task.
- If any check fails, review the cause and rectify the fault. After the fault is rectified, click Check Again.
For details about how to handle check failures, see the Checking Whether the Source Database Is Connected section in the Data Replication Service User Guide.
- If all check items are successful, click Next.
Figure 8 Task Check
You can proceed to the next step only when all check items are successful. If any alarms are generated, view and confirm the alarm details first before proceeding to the next step.
- If any check fails, review the cause and rectify the fault. After the fault is rectified, click Check Again.
- On the Confirm Task page, specify Start Time, select the check box before the agreement, and click Next.
- Set Start Time to Start upon task creation or Start at a specified time based on site requirements.
- After a migration task is started, the performance of the source and destination databases may be affected. You are advised to start a migration task during off-peak hours. If you have to migrate data during peak hours, you can select Yes for Flow Control to control the migration speed.
- After the task is submitted, go back to the Online Migration Management page to view the task status.
- Manage the migration task. The migration task contains two phases: full migration and incremental migration. You can manage them in different phases.
- Full migration
Viewing the migration progress: Click the target full migration task, and on the Migration Progress tab, you can see the migration progress. When the progress reaches 100%, the migration is complete.
- Incremental migration
- Viewing the synchronization delay: After the full migration is complete, an incremental migration starts. On the Online Migration Management page, click the target migration task. On the displayed page, click Migration Progress to view the synchronization delay of the incremental migration. If the synchronization delay is 0s, the destination database is being synchronized with the source database in real time. You can also view the data consistency on the Migration Comparison tab. Figure 9 Viewing the synchronization delay
- Viewing the migration results: On the Online Migration Management page, click the target migration task. On the displayed page, click Migration Comparison and perform a migration comparison in accordance with the comparison process, which should help you determine an appropriate time for migration to minimize service downtime. Figure 10 Database comparison process
For details, see the Comparing Migration Items section in the Data Replication Service User Guide.
- Viewing the synchronization delay: After the full migration is complete, an incremental migration starts. On the Online Migration Management page, click the target migration task. On the displayed page, click Migration Progress to view the synchronization delay of the incremental migration. If the synchronization delay is 0s, the destination database is being synchronized with the source database in real time. You can also view the data consistency on the Migration Comparison tab.
- Full migration
- Cut over services.
You are advised to start the cutover process during off-peak hours. Before the cutover, ensure that at least one complete data comparison is performed during off-peak hours. You can start a comparison at a specified time during off-peak hours to obtain more specific comparison results. Due to slight time difference and continuous operations on data, inconsistent comparison results may be generated, reducing the reliability and validity of the results.
- First, stop services. If the workload is not heavy, this may not be necessary.
- Run the following statement on the source database and check whether any new sessions execute SQL statements within the next 1 to 5 minutes. If there are no new statements executed, the service has been stopped.
db.currentOp()
The process list queried by the preceding statement includes the connection of the DRS replication instance. If no additional session executes SQL statements, the service has been stopped.
- On the Migration Progress page, view the synchronization delay. When the delay is displayed as 0s and remains stable for a period, then you can perform a data-level comparison between the source and destination databases. For details about the time required, refer to the results of the previous comparison.
- If there is enough time, compare all objects.
- If there is not enough time, use the data-level comparison to compare the tables that are frequently used and that contain key business data or inconsistent data.
- Determine an appropriate time to cut the services over to the destination database. After services are restored and available, the migration is complete.
- Stop or delete the migration task.
- Stopping the migration task. After databases and services are migrated to the destination database, to prevent operations on the source database from being synchronized to the destination database to overwrite data, you can stop the migration task. This operation only deletes the replication instance, and the migration task is still displayed in the task list. You can view or delete the task. DRS will not charge for this task after you stop it.
- Delete the migration task. After the migration task is complete, you can delete it. After the migration task is deleted, it will no longer be displayed in the task list.
Last Article: MySQL Database Migration
Next Article: Migrating On-Premises Databases to Cloud

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.