百度智能云

All Product Document

          Cloud Database MONGODB

          Connect to Replica Cluster Instance Through MongoShell

          Mongo Shell is a database management tool that comes with the MongoDB database. You can create a BCC in the VPC where the sharded cluster resides, install the Mongo Shell tool in the instance, and then connect to the sharded cluster instance through Mongo Shell.

          Prerequisites

          • To ensure successful authentication, you need to install the Mongo Shell version corresponding to the MongoDB instance version. For installation steps, refer to the official documentation Install MongoDB. You need to select the version number in the upper left corner of the page according to your client version.
          • The IP address of the client has been added to the whitelist of the MongoDB instance. For details, refer to Set Whitelist.

          Operating Steps

          1. Log in to the MongoDB management console.
          2. In the upper left corner of the page, select the region where the instance resides.
          3. In the left navigation bar, click Replica Cluster Instance List.
          4. Find the target instance, and click Instance Name.
          5. In the instance basic information, obtain the node connection address and instance address

          1. Connect to the instance in the following way on the client where Mongo Shell is installed.
          • Single-node connection mode

          During the routine test, you can directly connect to the Primary/Secondary nodes. Note that once the Primary-secondary switch occurs, the role of the connected node changes, resulting in the influence on the read and write operation.

          Command format:

          mongo --host <host> -u <username> -p --authenticationDatabase <database>
          Notes:
          <host>: The connection address of the Primary or Secondary node. 
          <username>: The database account of the MongoDB instance. The initial account is root.
          <database>: The name of the authentication database, that is, the database to which the database account belongs. When the database account is the root, the corresponding database is admin.

          Example

          mongo --host XQgIft8n4.mongodb.bj.baidubce.com:27017 -u root -p **** --authenticationDatabase admin

          Replace **** with the account password.

          • High-availability connection mode

          Using ConnectionStringURI to connect to the database can ensure that the connected node is always the Primary node, without any influence on the read and write operations of the application due to the switch between the primary and secondary nodes.

          Command format:

          mongo "ConnectionStringURI"

          Example:

          mongo "mongodb://root:****@XQgIftoqm.mongodb.bj.baidubce.com:27017,XQgIft8n4.mongodb.bj.baidubce.com:27017/admin?replicaSet=rep-zNo2RD"

          Replace **** with the account password.

          Previous
          Billing Management
          Next
          Connect to Sharded Cluster Instance Through MongoShell