You can install the Mongo shell in an ECS instance and use the mongo shell to connect to an ApsaraDB for MongoDB instance.
- For successful authentication, you must use mongo shell 3.0 or later to connect to an ApsaraDB for MongoDB instance. For more information about the installation procedure, see Install MongoDB.
- Add the server IP addresses that need access to the instance to the whitelist in advance. For more information, see Configure a whitelist.
- To log on to ApsaraDB for MongoDB over the Internet, you must apply for a public IP address. For more information, see Apply for a public IP address.
- Log on to the ApsaraDB for MongoDB console.
- In the upper-left corner of the homepage, select the region of the instance.
- In the left-side navigation pane, click Sharding instances.
- Locate the target instance, and then click the instance ID.
- On the Basic Information page that appears, click Database Connection in the left-side navigation pane to obtain the address of the mongos.
Three mongos are displayed in this example. You can use one of their addresses to log on to the mongos.
- Connect to a mongos from a local server or an ECS instance with mongo shell installed.
mongo --host <mongos_host> -u <username> -p --authenticationDatabase <database>Note
- <mongos_host>: the address of any mongos in the ApsaraDB for MongoDB instance.
- <username>: the account for the instance. The default username is root.
- <database>: the name of the authentication database for the local MongoDB database. The default database name is admin.
mongo --host s-bp**********.mongodb.rds.aliyuncs.com:3717 -u root -p --authenticationDatabase admin
Enter password:is displayed, enter the password. If you forget the password of the root account, you can reset the password by using the method specified in Set a password.Note The characters entered into the password field are not displayed.
We recommend that you do not log on to an ApsaraDB for MongoDB instance as the root user in the production environment. You can create users and grant permissions based on your business needs. For more information, see db.createUser().