All Products
Search
Document Center

ApsaraDB for MongoDB:Connect an ECS instance to a MongoDB instance across accounts

Last Updated:Aug 24, 2026

If your ECS instance and ApsaraDB for MongoDB instance are in different Alibaba Cloud accounts, use the methods in this topic to quickly establish an internal network connection between them.

Method 1: Migrate the MongoDB instance to the ECS instance's account

This method uses the data migration feature of Data Transmission Service (DTS) to migrate the MongoDB database to the account that contains the ECS instance.

Procedure

  1. In the Alibaba Cloud account that contains the ECS instance, create an ApsaraDB for MongoDB instance in the same Region, Availability Zone, and Proprietary Network as the ECS instance. For instructions, see Create an instance.

    Note
    • When you create the ApsaraDB for MongoDB instance, select the same VPC as the ECS instance.

    • If you have already created an ApsaraDB for MongoDB instance, skip this step.

  2. Migrate the MongoDB database from the source Alibaba Cloud account to the destination Alibaba Cloud account. For more information, see Migrate data between ApsaraDB for MongoDB instances of different Alibaba Cloud accounts.

  3. Add the IP address of the ECS instance to the destination ApsaraDB for MongoDB instance's IP address whitelist. For more information, see Modify an IP address whitelist.

    Note

    To obtain the IP address of the ECS instance, see View instance information.

Method 2: Migrate the ECS instance to the MongoDB instance's account

This method involves creating a custom image from the ECS instance and sharing it with the Alibaba Cloud account that contains the ApsaraDB for MongoDB instance. You then use the image to create a new ECS instance in that account.

Prerequisites

The ECS instance and the ApsaraDB for MongoDB instance must be in the same region.

Note

If the ECS instance and the ApsaraDB for MongoDB instance are in different regions, you can either copy the image to the destination region before sharing it, or share the image first and then copy it to the destination region. For instructions, see Copy a custom image.

Procedure

  1. Create a custom image from an instance.

  2. Share the custom image that you created with the Alibaba Cloud account that contains the ApsaraDB for MongoDB instance. For more information, see Share a custom image.

  3. Create an instance by using a custom image.

    Note

    When you create the ECS instance, select the same VPC as the ApsaraDB for MongoDB instance.

  4. Add the IP address of the new ECS instance to the ApsaraDB for MongoDB instance's IP address whitelist. For more information, see Modify an IP address whitelist.

    Note

    To obtain the IP address of the ECS instance, see View instance information.

Method 3: Connect instances with CEN

This method uses Cloud Enterprise Network (CEN) to establish a connection between VPCs in different Alibaba Cloud accounts, allowing the ECS instance and the ApsaraDB for MongoDB instance to connect with each other without a migration.

Note

Make sure that the CIDR blocks of the VPCs or vSwitches that you want to connect do not overlap.

Procedure

  1. Switch the network type of the ApsaraDB for MongoDB instance to VPC. For more information, see Switch the network type of an ApsaraDB for MongoDB instance from classic network to VPC. If the instance already uses a VPC, skip this step.

  2. Migrate ECS instances from a classic network to a VPC. If the instance already uses a VPC, skip this step.

  3. Choose a method to connect the VPCs by using CEN based on your environment. For more information, see the following documents:

  4. Add the IP address of the ECS instance to the ApsaraDB for MongoDB instance's IP address whitelist. For more information, see Modify an IP address whitelist.

    Note

    To obtain the IP address of the ECS instance, see View instance information.