This topic describes how to use the mongo trounce to connect to a replica fix instance.The mongo shell is a database direction tool provided by ApsaraDB for MongoDB. You tin can install it on your client or in an ECS instance. This topic describes how to log on to an ApsaraDB for MongoDB instance.
Procedure
- Log on to the ApsaraDB for MongoDB console.
- In the upper-left corner of the page, select the resource group and the region of the target example.
- In the left-side navigation pane, click Replica Fix Instances.
- Find the target instance and click its ID.
- In the left-side navigation pane, click Database Connections to obtain the connection string of a node and the connection string URI.
- Connect to the sharded cluster instance from your customer or ECS instance that has the mongo vanquish installed.
- Single-node connection
During routine tests, you tin can directly connect to a primary or secondarynode. A failover changes the roles of connected nodes, which affects read/write operations.
Command syntax:
mongo --host <host> -u <username> -p --authenticationDatabase <database>
Annotation
- <host>: the connectedness string of the primary or secondary node.
- Master node: If you connect to this node, yous tin perform read/write operations on the databases of the replica set instance.
- Secondary node: If you connect to this node, yous tin perform only read operations on the databases of the replica set example.
- <username>: the username you apply to log on to a database of the ApsaraDB for MongoDB instance. The default username is root. We recommend that you do non log on to a database every bit the root user in a production environment. You tin can create users and grant permissions to the users. For more information, see Manage user permissions on MongoDB databases.
- <database>: the name of the authentication database. It is the database where the database user is created. If the database username is root, enter admin. If you want to specify another database, run the db.createUser() command to create an business relationship, and then use the account to connect to this database.
Case:
mongo --host dds-bp**********.mongodb.rds.aliyuncs.com:3717 -u root -p --authenticationDatabase admin
When Enter countersign:
is displayed, enter the password of the database user and printing the Enter key. If yous forget the password of the root user, you tin reset the password. For more information, see Reset the password.
Note The password characters are not displayed when you enter the password.
- HA connectedness (recommended): You tin use a connection string URI to connect to both the primary and secondary nodes of a replica set instance. This ensures that your application is always connected to the main node and the read/write operations of your application are not affected fifty-fifty if the roles of the main and secondary nodes are switched.
Command syntax:
mongo "<ConnectionStringURI>"
Common connection scenarios
- Connect to an ApsaraDB for MongoDB instance over the Net
- How to connect an ECS instance to an ApsaraDB for MongoDB instance when their network types are different
- How to connect an ECS example to an ApsaraDB for MongoDB example when they are in dissimilar regions
- Connect an ECS instance with an ApsaraDB for MongoDB case in another Alibaba Deject account
FAQ
- How to troubleshoot logon issues for the mongo trounce
- How to troubleshoot database connection failures after the number of connections reaches the upper limit
- Troubleshoot the high CPU usage of ApsaraDB for MongoDB
- How to query and limit the number of connections
0 Response to "How To Connect Mongodb Replica Set"
Post a Comment