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 URI of a sharded cluster instance. This topic also describes how to log on to a specific database of a sharded cluster instance.
View the connection strings and URI of a sharded cluster instance
- Log on to the ApsaraDB for MongoDB console.
- In the left-side navigation pane, click Sharded Cluster Instances.
- In the upper-left corner of the page, select the resource group and region to which the instance belongs.
- Click the ID of an instance, or click
in the Actions column corresponding to the instance and select Manage.
- In the left-side navigation pane of the instance details page, click Database Connections. Obtain the connection information of the node.
Introduction to connection strings and URIs
Item | Description |
---|---|
Connection address type |
|
Connection string | For mongos, shard, and Configserver nodes, connection strings are provided for both
primary and secondary nodes. For shard modes, connection strings are also provided
for read-only nodes.
Note The connection string of a read-only node is displayed only if the instance contains
the read-only node.
Format:
The following table describes the parameters used in the syntax.
Example:
Note For routine tests, you can connect only to either primary or secondary node of a mongos
node. To connect to a shard node or a Configserver node, you must apply for a connection
string for the node. For more information, see Apply for an endpoint for a shard or Configserver node
|
URI |
Important If your application is deployed in a production environment, we recommend that you
use the URI to connect to the sharded cluster instance. This way, your client can
automatically distribute requests to primary and secondary nodes of mongos nodes to
balance the loads within the sharded cluster instance. If the priamry or secondary
node of the mongos node fails, your client can automatically redirect requests to
the other healthy node.
The following table describes the parameters used in the syntax.
Example:
|
Log on to a specific database of a sharded cluster instance
Common connection scenarios
- Connect to an ApsaraDB for MongoDB instance over the Internet
- Connect an ECS instance to an ApsaraDB for MongoDB instance when their network types are different
- How to connect an ECS instance to an ApsaraDB for MongoDB instance when they are in different regions
- Connect an ECS instance with an ApsaraDB for MongoDB instance in another Alibaba Cloud account