This topic describes how to connect to an ApsaraDB for MongoDB instance over the public internet.
Prerequisites
-
The public IP address of your local client.
-
You have added the public IP address of your local client to the instance's allowlist.
Step 1: Apply for a public connection string
-
Go to the Replica Set Instances or Sharded Cluster Instances page. In the top navigation bar, select the desired resource group and region. Then, click the ID of the target instance.
-
In the left-side navigation pane of the instance details page, click Database Connections.
-
In the Public IP Connection section, click Apply for Public IP.
-
In the Apply for Public IP dialog box, click Confirm.
-
Wait for the instance status to change from Establishing Network Connection to Running. You can then view the public connection string of the instance.
Note-
The instance continues to run normally while its status is Establishing Network Connection.
-
The connection string is visible only after you configure the allowlist.
-
Use the ConnectionStringURI for a high-availability connection.
-
Step 2: Connect to the instance
This example uses the MongoDB Shell (mongosh) to connect to the instance.
ConnectionStringURI (Recommended)
Command:
mongo "<ConnectionStringURI>"
Parameters:
|
Parameter |
Description |
|
|
The ConnectionStringURI for your instance, available in the ApsaraDB for MongoDB console. Note
As a security best practice, do not connect to the database using the root account. Create a database account in Data Management (DMS) before you connect. When you connect, replace |
Example:
mongo "mongodb://test:PassWord**@dds-bp19f409d7512****.mongodb.rds.aliyuncs.com:3717,dds-bp19f409d7512****.mongodb.rds.aliyuncs.com:3717,dds-bp19f409d7512****.mongodb.rds.aliyuncs.com:3717/testdb?replicaSet=mgset-6108****"
Single-node connection string
Command:
mongo --host <host> --port <port> -u <username> -p --authenticationDatabase <authenticationDatabase>
Parameters:
|
Parameter |
Description |
|
|
The Connection Address and Port of the node, available in the ApsaraDB for MongoDB console. Example: |
|
|
The name of the database account. Note
As a security best practice, do not use the root account to connect to the database. Create a database account in Data Management (DMS) before you connect. |
|
|
The database used to authenticate the specified database account. Important
For authentication to succeed, the database account must be authenticated against the database to which it belongs. |
Example:
The following example assumes the database account is test and the authentication database is testdb.
mongo --host dds-bp19f409d7512****.mongodb.rds.aliyuncs.com --port 3717 -u test -p --authenticationDatabase testdb
At the Enter password: prompt, enter the password for the database account and press Enter.