This topic describes how to enable or disable password-free access over a virtual private cloud (VPC) for an ApsaraDB for MongoDB instance. This allows for easy and secure connection to databases. After password-free access over a VPC is enabled for an ApsaraDB for MongoDB instance, the Elastic Compute Service (ECS) instance that shares the same VPC with the ApsaraDB for MongoDB instance can connect to a database of this ApsaraDB for MongoDB instance without a password. You can still use a database username and its password to connect to this database.

Prerequisites

The instance is a replica set or sharded cluster instance that runs MongoDB 4.0 (minor version: mongodb_20190408_3.0.11 or later) or 4.2, or the instance is a replica set instance that runs MongoDB 5.0 or 4.4. If your MongoDB version is earlier than required, upgrade the MongoDB version. For more information, see Upgrade MongoDB versions and Upgrade the minor version of an ApsaraDB for MongoDB instance.
Note
  • Standalone instances do not support password-free access over a VPC.
  • You can view the major version and minor version of an instance on the Basic Information page in the ApsaraDB for MongoDB console.

Enable or disable password-free access over a VPC for an ApsaraDB for MongoDB instance

  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Replica Set Instances, or Sharded Cluster Instances based on the instance type.
  4. Find the target instance and click its ID.
  5. In the left-side navigation pane, click Database Connections.
  6. In the upper-right corner of the Internal Connections - VPC section, click Enable Password-free Access or Disable Password-free Access.
    • Enable password-free access over a VPC
      Note If you want to connect to a database of an ApsaraDB for MongoDB instance without a password, add the IP address of your client to a whitelist of this instance. For more information, see Configure a whitelist or an ECS security group for an ApsaraDB for MongoDB instance.

      After password-free access over a VPC is enabled for an ApsaraDB for MongoDB instance, the ECS instance that shares the same VPC with the ApsaraDB for MongoDB instance can connect to a database of this ApsaraDB for MongoDB instance without a password. For more information, see What is ECS? You can still use a database username and its password to connect to this database.

      Enable password-free access over a VPC
      The following command provides an example of a password-free connection by using the mongo shell:
      mongo --host dds-bpxxxxxxxx.mongodb.rds.aliyuncs.com:3717
    • Disable password-free access over a VPC
      Note After password-free access over a VPC is disabled, the applications that have established connections with a database of this ApsaraDB for MongoDB instance are disconnected. You must change the database connection mode for your applications before you disable password-free access.
      Disable password-free access over a VPC
  7. In the message that appears, click Confirm.

Related API operations

Operation Description
ModifyInstanceVpcAuthMode Enables or disables password-free access over a VPC for an ApsaraDB for MongoDB instance.