This topic describes how you can switch the network type of an ApsaraDB for MongoDB instance from a classic network to a virtual private cloud (VPC) by using the console or by calling the relevant API operation. When you switch the network type, you can specify a period for which you want to retain the classic network endpoint of the instance. After the retention period expires, the classic network endpoint is automatically deleted.

Prerequisites

Before you switch the network type, make sure that the following requirements are met:
  • An Alibaba Cloud account is created. If you do not have an Alibaba Cloud account, create one. For more information, seeCreate an Alibaba Cloud account.
  • The network type is the classic network.
  • The instance must be an ApsaraDB for MongoDB replica set instance.
  • VPCs and VSwitches are available in the zone to which the ApsaraDB for MongoDB instance belongs. For more information, see Create a VPC.

Switch the network type by using the console

  1. Log on to the ApsaraDB for MongoDB console.
  2. Find the instance that you want to manage, and click the instance ID or click Manage in the Actions column.
  3. In the left-side navigation pane, click Database Connection, and click Switch to VPC.
  4. In the dialog box that appears, perform the following steps:
    1. Select the VPC and VSwitch that you want to use.
    2. You can choose to retain a classic network endpoint and specify a retention period.
      Note After you select to retain the classic network endpoint, classic-network ECS instances can access the database. When the classic network endpoint expires, it is automatically deleted and you cannot access the database through the classic network endpoint.
    3. Click OK.
  5. You can click Refresh on the Database Connection page to view the endpoints of the classic network and VPC.

Switch the network type by calling the required API operation

  1. Download an SDK that meets your business requirements. The following SDKs are available:
  2. Call the ModifyDBInstanceNetworkType operation to switch the network type.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to

    ModifyDBInstanceNetworkType

    DBInstanceId String Yes The ID of the instance.
    NetworkType String Yes The network type of the instance. Valid values:
    • VPC: The instance runs in a VPC.
    • Classic: a classic network.
    VPCId String No The ID of the VPC.
    VSwitchId String No

    The ID of the VSwitch.

    This parameter is required if the VPC ID is specified.

    RetainClassic String No
    Specifies whether to retain the classic network endpoint. Default value: False:
    • True: The classic network endpoint is retained.
    • False: The classic network endpoint is not retained.
    ClassicExpiredDays String No

    The retention period of the classic network endpoint in days. The retention period of the classic network endpoint in days. Unit: days. Minimum value: 1. Maximum value: 120. Default value: 7.

    This parameter is required if RetainClassic is set to True.

    Response parameters
    Parameter Type Description
    RequestId String The ID of the request.
    TaskId String The ID of the task.
  3. You can call the DescribeReplicaSetRole operation to view the classic network endpoint and the VPC endpoint.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to

    DescribeReplicaSetRole

    DBInstanceId String Yes The ID of an instance.
    Response parameters
    Parameter Type Description
    ReplicaSets List The list of replica set roles.
    DBInstanceId String The ID of the instance.
    ReplicaSetRole
    Parameter Type Description
    ReplicaSetRole String The replica set role. Valid values: Primary and Secondary.
    ConnectionDomain String The domain name that is used to connect to the instance.
    ConnectionPort String The port number that is used to connect to the instance.
    ExpiredTime String The remaining period for the classic network endpoint. Unit: seconds.
    NetworkType String The network type of the instance. Valid values:
    • VPC: a VPC network
    • Classic: a classic network