ApsaraDB for MongoDB provides a connection string for each mongos node, each shard node, and the ConfigServer node in a sharded cluster instance. ApsaraDB for MongoDB also provides a Uniform Resource Identifier (URI) for each sharded cluster instance. The URI of a sharded cluster instance is used to establish a highly available connection between your application and the instance. This topic describes how to view the connection strings and URIs of a sharded cluster instance and how to log on to a specific database of a sharded cluster instance.
View the connection strings and URIs of a sharded cluster instance
Go to the Sharded Cluster Instances page. In the top navigation bar, select the region in which the instance resides. Then, find the instance and click the ID of the instance.
In the left-side navigation pane of the instance details page, click Database Connections. In the page that appears, view the connection information of a node in the instance.
Connection strings and URIs
Item | Description |
Endpoint type |
|
SRV high availability endpoint | Important
Format:
Parameters in the preceding command:
Example: In the following sample command, the username is test and the database is admin.
|
Connection string URI | Important If your application is deployed in a production environment, we recommend that you use a URI to connect to the sharded cluster instance. This way, your client can automatically distribute requests to mongos nodes to balance the loads within the sharded cluster instance. If a mongos node fails, your client can automatically redirect requests to other healthy mongos nodes. Format:
Parameters in the preceding command:
Example: In the following sample command, the username is test and the database is admin.
|
Connection string | The following types of connection strings are supported:
Note
Format:
Parameters in the preceding command:
Example:
|
Log on to a specific database of a sharded cluster instance
Obtain the following information:
The connection strings or URIs of the sharded cluster instance. For more information, see View the connection strings and URIs of a sharded cluster instance.
The database account that is used to connect to the sharded cluster instance. The initial account is the root account.
ImportantWe recommend that you do not connect to a database in the production environment by using the root account. You can create database accounts and grant permissions to the accounts based on your business requirements. For more information, see Manage the permissions of MongoDB database users.
The password of the database account that is used to connect to the sharded cluster instance. If you do not specify a password for the database account or you forget the password of the account, you can set or change the password of the account. For more information, see (Optional) Reset a password.
The name of the database to which you want to connect. If the username is root, enter admin.
Log on to a database For more information, see the following topics: