This topic describes how to use DTS to migrate data from a MongoDB Atlas database to ApsaraDB for MongoDB. DTS supports both full data migration and incremental data migration. You can select both migration types to enable a smooth migration with zero downtime.
Prerequisites
The ApsaraDB for MongoDB instance should have at least 10% more storage space than the MongoDB Atlas database.
Notes
-
During a full data migration, DTS consumes resources from both the source and destination databases, increasing the load on the database servers. If your database has a high workload or your servers have low specifications, the increased load may impact database performance and even cause the service to become unavailable. Carefully evaluate the potential impact and perform the data migration during off-peak hours.
-
DTS does not support migrating the admin and local databases.
-
The config database is an internal system database. Do not migrate it unless you have specific requirements.
-
For information about the versions and storage engines supported by ApsaraDB for MongoDB, see MongoDB versions and storage engines. If you migrate data across different versions or storage engines, you must confirm compatibility beforehand.
-
Because DTS writes data concurrently, the destination database requires 5% to 10% more storage space than the source database.
-
To prevent data loss, ensure that no documents in the destination database have primary keys that conflict with those in the source database. The default primary key is _id. If the destination database contains documents with such conflicting primary keys, you must delete them before starting the migration. Ensure this deletion does not impact your services.
Billing
|
Migration type |
Instance configuration fee |
Internet traffic fee |
|
Full data migration |
Free. |
Charges apply for migrating data from Alibaba Cloud over the internet. For more information, see billing overview. |
|
Incremental data migration |
Charged. For more information, see billing overview. |
Migration types
| Migration type | Description |
| Full data migration | Migrates all historical data of the selected objects from the source MongoDB database to the destination MongoDB database. Note DTS supports the migration of databases, collections, and indexes. |
| Incremental data migration | After a full data migration, DTS synchronizes incremental data updates from the source MongoDB database to the destination MongoDB database. Note
|
Permission requirements for database accounts
|
Database |
Full data migration |
Incremental data migration |
|
MongoDB Atlas database |
The |
|
|
ApsaraDB for MongoDB instance |
The |
The |
To create a database account and grant permissions to the account, see the following topics:
-
MongoDB Atlas database: MongoDB user creation instructions.
-
ApsaraDB for MongoDB instance: Use DMS to manage database accounts.
Before you begin
-
Log in to the MongoDB Atlas console.
-
From the navigation pane on the left, click Network Access.
-
On the IP access list tab, click Add IP Address.
-
Add the DTS service IP addresses for your region to the IP access list. For more information, see Add IP access list entries and Add DTS server IP addresses to an allowlist.
NoteThis step grants DTS access to your MongoDB Atlas database. Delete the rule after the migration finishes.
Procedure (new console)
-
Navigate to the migration task list page for the destination region using one of the following methods.
From the DTS console
-
Log on to the Data Transmission Service (DTS) console.
-
In the navigation pane on the left, click Data Migration.
-
In the upper-left corner of the page, select the region where the migration instance is located.
From the DMS console
NoteThe actual operations may vary based on the mode and layout of the DMS console. For more information, see Simple mode console and Customize the layout and style of the DMS console.
-
Log on to the Data Management (DMS) console.
-
In the top menu bar, choose .
-
To the right of Data Migration Tasks, select the region where the migration instance is located.
-
-
Click Create Task to navigate to the task configuration page.
-
Configure the source and destination databases.
WarningAfter you select the source and destination instances, we recommend that you carefully read the limits displayed at the top of the page. Otherwise, the task may fail or data inconsistency may occur.
Category
Parameter
Description
N/A
Task Name
DTS automatically generates a task name. We recommend that you specify a descriptive name for easy identification. The name does not need to be unique.
Source Database
Select a DMS database instance.
You can choose whether to use an existing instance, as needed.
-
If you use an existing instance, the database information below is automatically filled in. You do not need to enter it again.
-
If you do not use an existing instance, you must configure the database information below.
Note-
In the DMS console, you can click Add DMS Database Instance to register a database with DMS. For more information, see ApsaraDB Data Ingestion and Register a database hosted on a third-party cloud service or a self-managed database.
-
In the DTS console, you can register a database with DTS on the Database Connections page or the new configuration page. For more information, see Manage database connections.
Database Type
Select MongoDB.
Connection Type
Select Public IP Address.
Instance Region
Select the region of the MongoDB Atlas database.
NoteIf the database's region is not listed, select the geographically closest region.
Architecture
Select Replica Set.
Domain Name or IP
Enter the endpoint of the PRIMARY node in the MongoDB Atlas database.
NoteYou can obtain the endpoint in the MongoDB Atlas console.
Port
Enter the service port of the MongoDB Atlas database. The default value is 27017.
Authentication Database
Enter the name of the authentication database in which the database account is created.
Database Account
Enter the database account of the MongoDB Atlas database. For more information about the required permissions, see Permissions required for database accounts.
Database Password
Enter the password for the database account.
Connection Method
Select Mongo Atlas SSL.
Destination Database
Select a DMS database instance.
You can choose whether to use an existing instance, as needed.
-
If you use an existing instance, the database information below is automatically filled in. You do not need to enter it again.
-
If you do not use an existing instance, you must configure the database information below.
Note-
In the DMS console, you can click Add DMS Database Instance to register a database with DMS. For more information, see ApsaraDB Data Ingestion and Register a database hosted on a third-party cloud service or a self-managed database.
-
In the DTS console, you can register a database with DTS on the Database Connections page or the new configuration page. For more information, see Manage database connections.
Database Type
Select MongoDB.
Connection Type
Select Cloud instance.
Instance Region
Select the region of the destination Alibaba Cloud MongoDB instance.
Architecture
Select an architecture type based on your business requirements. Valid values:
-
Replica Set: Replica set instances use multiple node types to implement high availability and read/write splitting. For more information, see Replica set instances.
-
Sharded Cluster: A sharded cluster instance consists of three types of components: mongos, shard, and Configserver nodes. You can customize the configurations and number of mongos and shard nodes. For more information, see Sharded cluster instances.
Instance ID
Select the instance ID of the destination Alibaba Cloud MongoDB instance.
Authentication Database
Enter the name of the authentication database where the database account is created.
NoteIf you use the root account, the corresponding database name is admin.
Database Account
Enter the database account of the destination Alibaba Cloud MongoDB instance. For more information about the required permissions, see Permissions required for database accounts.
Database Password
Enter the password for the database account.
-
-
After you complete the configuration, click Test Connectivity and Proceed at the bottom of the page. In the CIDR Blocks of DTS Servers dialog box that appears, click Test Connectivity.
NoteEnsure that the IP address segments of the DTS service are automatically or manually added to the security settings of the source and destination databases to allow access from DTS servers. For more information, see Add DTS server IP addresses to a whitelist.
-
Configure the task objects.
-
On the Configure Objects page, configure the objects that you want to migrate.
Parameter
Description
Migration Types
-
If you only need to perform a full migration, select both Schema Migration and Full Data Migration.
-
To perform a migration with no downtime, select Schema Migration, Full Data Migration, and Incremental Data Migration.
Note-
If you do not select Schema Migration, you must ensure that a database and tables to receive the data exist in the destination database. You can also use the object name mapping feature in the Selected Objects box as needed.
-
If you do not select Incremental Data Migration, do not write new data to the source instance during data migration to ensure data consistency.
Processing Mode of Conflicting Tables
- Precheck and Report Errors: checks whether the destination database contains collections that have the same names as collections in the source database. If the source and destination databases do not contain collections that have identical collection names, the precheck is passed. Otherwise, an error is returned during the precheck and the data synchronization task cannot be started. Note You can use the object name mapping feature to rename the collections that are synchronized to the destination database. You can use this feature if the source and destination databases contain identical collection names and the collections in the destination database cannot be deleted or renamed. For more information, see Rename synchronized objects in the destination instance.
- Ignore Errors and Proceed: skips the precheck for identical collection names in the source and destination databases. Warning If you select Ignore Errors and Proceed, data inconsistency may occur, and your business may be exposed to potential risks.
- DTS does not synchronize data records that have the same primary key values as data records in the destination database.
- Data may fail to be initialized, only some columns are synchronized, or the data synchronization task fails.
Capitalization of Object Names in Destination Instance
You can configure the case policy for database and collection object names in the destination instance. By default, the DTS default policy is selected. Alternatively, you can match the default policy of the source or destination database. For more information, see Case policy for destination object names.
Source Objects
Select one or more objects from the Source Objects section. Click the
icon and add the objects to the Selected Objects section. NoteYou can select objects at the granularity of databases or collections.
Selected Objects
-
To change the name of a single migration object in the target instance, right-click the object in the Selected Objects box. For more information, see Map individual schema, table, and column names.
-
To change the names of multiple migration objects in the target instance, click Selected Objects in the upper-right corner of the Batch Edit box. For more information, see Map multiple schema, table, and column names.
Note-
If you use the object name mapping feature to rename an object, other objects that depend on the object may fail to migrate.
-
To specify WHERE conditions to filter data, right-click an object in the Selected Objects box. In the dialog box that appears, specify the conditions. For more information, see Set filter conditions.
-
-
Click Next: Advanced Settings to configure advanced parameters.
Parameter
Description
Retry Time for Failed Connections
After the migration task starts, if the connection to the source or destination database fails, DTS reports an error and immediately begins to retry the connection. The default retry duration is 720 minutes. You can customize the retry time to a value from 10 to 1440 minutes. We recommend that you set the duration to more than 30 minutes. If DTS reconnects to the source and destination databases within the specified duration, the migration task automatically resumes. Otherwise, the task fails.
Note-
For multiple DTS instances that share the same source or destination, the network retry time is determined by the setting of the last created task.
-
Because you are charged for the task during the connection retry period, we recommend that you customize the retry time based on your business needs, or release the DTS instance as soon as possible after the source and destination database instances are released.
Retry Time for Other Issues
After the migration task starts, if a non-connectivity issue, such as a DDL or DML execution exception, occurs in the source or destination database, DTS reports an error and immediately begins to retry the operation. The default retry duration is 10 minutes. You can customize the retry time to a value from 1 to 1440 minutes. We recommend that you set the duration to more than 10 minutes. If the related operations succeed within the specified retry duration, the migration task automatically resumes. Otherwise, the task fails.
ImportantThe value of Retry Time for Other Issues must be less than the value of Retry Time for Failed Connections.
Enable Throttling for Full Data Migration
During full migration, DTS consumes read and write resources on the source and destination databases, which may increase the database load. If required, you can enable throttling for the full migration task. You can set Queries per second (QPS) to the source database, RPS of Full Data Migration, and Data migration speed for full migration (MB/s) to reduce the load on the destination database.
Note-
This configuration item is available only if you select Full Data Migration for Migration Types.
-
You can also adjust the full migration speed after the migration instance is running.
Enable Throttling for Incremental Data Migration
If required, you can also choose to set speed limits for the incremental migration task. You can set RPS of Incremental Data Migration and Data migration speed for incremental migration (MB/s) to reduce the load on the destination database.
Note-
This configuration item is available only if you select Incremental Data Migration for Migration Types.
-
You can also adjust the incremental migration speed after the migration instance is running.
Environment Tag
You can select an environment tag to identify the instance based on your business requirements. In this example, you do not need to select a value.
Configure ETL
Based on your business needs, select whether to configure the ETL feature to process data.
-
Yes: Configures the ETL feature. You must also enter data processing statements in the text box.
-
No: Does not configure the ETL feature.
Monitoring and Alerting
Select whether to set alerts and receive alert notifications based on your business needs.
-
No: Does not set an alert.
-
Yes: Configure alerts by setting an alert threshold and an alert notifications. If a migration fails or the latency exceeds the threshold, the system sends an alert notification.
-
-
Click Next: Data Validation to configure a data validation task.
For more information about the data validation feature, see Configure data validation.
-
-
Save the task and run a precheck.
-
To view the parameters for configuring this instance when you call the API operation, move the pointer over the Next: Save Task Settings and Precheck button and click Preview OpenAPI parameters in the bubble that appears.
-
If you do not need to view or have finished viewing the API parameters, click Next: Save Task Settings and Precheck at the bottom of the page.
Note-
Before the migration task starts, DTS performs a precheck. The task starts only after it passes the precheck.
-
If the precheck fails, click View Details next to the failed check item, fix the issue based on the prompt, and then run the precheck again.
-
If a warning is reported during the precheck:
-
For check items that cannot be ignored, click View Details next to the failed item, fix the issue based on the prompt, and then run the precheck again.
-
For check items that can be ignored, you can click Confirm Alert Details, Ignore, OK, and Precheck Again to skip the alert item and run the precheck again. If you choose to ignore a warning, it may cause issues such as data inconsistency and pose risks to your business.
-
-
-
Purchase the instance.
-
When the Success Rate is 100%, click Next: Purchase Instance.
-
On the Purchase page, select the link specification for the data migration instance. For more information, see the following table.
Category
Parameter
Description
New Instance Class
Resource Group Settings
Select the resource group to which the instance belongs. The default value is default resource group. For more information, see What is Resource Management?
Instance Class
DTS provides migration specifications with different performance levels. The link specification affects the migration speed. You can select a specification based on your business scenario. For more information, see Data migration link specifications.
-
After the configuration is complete, read and select Data Transmission Service (Pay-as-you-go) Service Terms.
-
Click Buy and Start. In the OK dialog box that appears, click OK.
You can view the progress of the migration task on the Data Migration Tasks list page.
Note-
If the migration task does not include incremental migration, it stops automatically after the full migration is complete. After the task stops, its Status changes to Completed.
-
If the migration task includes incremental migration, it does not stop automatically. The incremental migration task continues to run. While the incremental migration task is running, the Status of the task is Running.
-
-
Procedure (old console)
-
Purchase a data migration instance. For more information, see Purchase a DTS instance.
-
Log on to the DTS console.
NoteIf you are automatically redirected to the Data Management (DMS) console, you can click the
icon in the lower-right corner and then click
to return to the classic DTS console. -
In the navigation pane on the left, click Data Migration.
-
At the top of the Migration Tasks page, select the region where the destination ApsaraDB for MongoDB instance is located.
-
Find the data migration instance you purchased and click Configure Data Migration Task.
-
Configure the source and destination databases.
Section
Parameter
Description
N/A
Task name
DTS automatically generates a task name. We recommend specifying a descriptive name for easy identification. The task name does not need to be unique.
Source database
Instance type
Select User-created database with public IP address.
Instance region
If you select User-created database with public IP address as the Instance Region, you do not need to configure this parameter.
Database type
Select MongoDB.
Hostname or IP address
Enter the endpoint of the PRIMARY node in the MongoDB Atlas database.
To obtain the endpoint from the MongoDB Atlas console:
In the left navigation pane, click Clusters. Find the target cluster, such as Cluster0, and click CONNECT. You can then view and copy the endpoint of the PRIMARY node.
Port number
Enter the service port number of the MongoDB Atlas database. The default value is 27017.
Database name
Enter the name of the authentication database where the database account is created.
Database account
Enter the account of the MongoDB Atlas database. For information about the required permissions, see Permissions required for database accounts.
Database password
Enter the password of the database account.
NoteAfter you enter the source database information, you can click Test Connectivity next to Database Password to verify that the entered source database information is correct. If the information is correct, a Passed message is displayed. If a Failed message is displayed, click Diagnose next to Failed and adjust the source database information based on the prompts.
Connection method
Select SSL-encrypted.
Destination database
Instance type
Select MongoDB Instance.
Instance region
Select the region where the destination ApsaraDB for MongoDB instance is located.
MongoDB instance ID
Select the ID of the destination ApsaraDB for MongoDB instance.
Database name
Enter the name of the authentication database where the database account is created.
NoteIf you use the root account, the corresponding database name is admin.
Database account
Enter the database account of the destination ApsaraDB for MongoDB instance. For information about the required permissions, see Permissions required for database accounts.
Database password
Enter the password of the database account.
NoteAfter you configure the destination database, you can click Test Connectivity next to Database Password to verify the information. If the information is correct, a Passed message appears. If a Failed message appears, click Diagnose next to Failed and modify the information as prompted.
-
After you complete the preceding configurations, click Authorize Whitelist and Go to Next Step in the lower-right corner of the page.
If the source or destination database is an Alibaba Cloud database instance, such as an ApsaraDB RDS for MySQL or ApsaraDB for MongoDB instance, DTS automatically adds the CIDR blocks of DTS servers to the IP address whitelist of the instance. If the source or destination database is a user-created database on an ECS instance, DTS automatically adds the CIDR blocks of DTS servers to the security group rules of the ECS instance. You must also ensure that the user-created database allows access from the ECS instance. If the database is a cluster on multiple ECS instances, you must manually add the DTS server CIDR blocks for the relevant region to the security group rules of each ECS instance. If the source or destination database is a user-created database in a data center or hosted on another cloud platform, you must manually add the CIDR blocks of DTS servers to allow access from DTS servers. For the CIDR blocks of DTS servers, see CIDR blocks of DTS servers.
WarningAdding the public CIDR blocks of DTS servers, whether automatically or manually, may introduce security risks. By using this product, you acknowledge and accept these potential risks. You are responsible for implementing basic security measures, including but not limited to using strong passwords, restricting open ports, using authentication for internal API calls, regularly reviewing and restricting unnecessary network segments, or connecting through private networks such as Express Connect, VPN Gateway, or Smart Access Gateway.
-
Select the migration types and objects.
Parameter
Description
Migration type
-
For a full data migration, select Full data migration.
-
For a migration with minimal downtime, select both Full data migration and Incremental data migration.
NoteTo ensure data consistency, do not write new data to the source database during a full-only migration (when Incremental data migration is not selected).
Migration objects
-
In the Available section, select the objects that you want to migrate, and then click
to move them to the Selected Objects section.NoteYou cannot migrate the admin, local, or config databases.
-
You can migrate databases, collections, or functions.
-
Migration object names are unchanged by default. To rename an object in the destination ApsaraDB for MongoDB database, use the object name mapping feature. For more information, see Object name mapping.
Map or change object names
To rename a migration object in the destination instance, use the object name mapping feature. For more information, see Object name mapping.
Connection retry duration
Specifies the period for which DTS retries to connect to a disconnected database. The default value is 12 hours. You can specify a custom duration. If DTS reconnects to the source and destination databases within the specified period, the migration task automatically resumes. Otherwise, the task fails.
NoteYou are charged for the DTS instance while DTS retries the connection. We recommend that you specify a retry duration based on your business requirements, or release the DTS instance as soon as the source and destination instances are released.
-
After you complete the configuration, click Precheck and Start in the lower-right corner of the page.
Note-
Before the migration task starts, DTS runs a precheck. 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 as prompted and run the precheck again.
-
If you do not need to fix the warning items, you can select Ignore and then click Ignore Warnings and Rerun Precheck to run the precheck again.
-
-
-
After the task passes the precheck, click Next.
-
On the Confirm Settings page, select an Instance Class and select the Data Transmission Service (Pay-As-You-Go) Service Terms check box.
-
Click Buy and Start to start the migration task.
-
Full data migration
Do not manually stop the migration task. Otherwise, the migrated data may be incomplete. Wait until the migration task automatically stops.
-
Incremental data migration
The migration task does not automatically stop. You must manually stop it.
NoteWe recommend that you manually stop the task at an appropriate time, such as during off-peak hours or before you switch your business to the destination ApsaraDB for MongoDB instance.
-
When the progress of the migration task changes to Incremental Data Migration and the status is Undelayed, stop writing to the source database for a few minutes. At this point, the status of the Incremental Data Migration may show a latency.
-
Wait for the Incremental Data Migration of the migration task to enter the Undelayed state again, and then manually end the migration task. At this point, the task status is Migrating, and the full data migration progress is 100%.
-
-
-
Switch your applications to the destination ApsaraDB for MongoDB instance.