If your Elastic Compute Service (ECS) instance and ApsaraDB for MongoDB instance are in different network types — one in a classic network and the other in a virtual private cloud (VPC) — use the options on this page to establish a connection.
Prerequisites
Before you begin, make sure that:
-
The ECS instance and the ApsaraDB for MongoDB instance belong to the same Alibaba Cloud account and are deployed in the same region.
-
The IP address of the ECS instance is added to all IP address whitelists of the ApsaraDB for MongoDB instance. For more information, see Modify an IP address whitelist of an ApsaraDB for MongoDB instance.
To find the IP address of an ECS instance, see View instance information.
Connection options
Identify your scenario, then follow the corresponding option.
Scenario 1: ECS in a classic network, MongoDB in a VPC
Option A (recommended): Migrate the ECS instance to the VPC
Move the ECS instance into the same VPC as the ApsaraDB for MongoDB instance. This provides a stable, high-speed private connection suitable for production.
For migration steps, see Migrate an ECS instance from a classic network to a VPC.
Option B: Use ClassicLink
ClassicLink allows a classic-network ECS instance to communicate with VPC resources over private IP addresses without moving the instance. Use this as a temporary workaround — for production, deploy both instances in the same VPC.
Before enabling ClassicLink, review its limits in Overview. For setup steps, see Use ClassicLink to connect a classic network to a VPC.
Scenario 2: ECS in a VPC, MongoDB in a classic network
Replica set and sharded cluster instances purchased on or after February 21, 2022 cannot be deployed in a classic network. Only VPC deployment is supported. For details, see [Notice] Classic network unavailability for new ApsaraDB for MongoDB instances.
Migrate the ApsaraDB for MongoDB instance to the VPC that the ECS instance is in. For migration steps, see Switch the network type of an ApsaraDB for MongoDB instance from classic network to VPC.
Keep in mind:
-
Standalone instances do not support network type changes.
-
A transient disconnection occurs during the switch. Perform this operation during off-peak hours, or make sure your application can automatically reconnect to the database.