This topic describes how to connect to a sharded cluster instance by using the mongo shell. The mongo shell is a database management tool that comes with MongoDB. You can install the mongo shell on your client or in an ECS instance.



  1. Log on to the ApsaraDB for MongoDB console.
  2. In the upper-left corner of the page, select the resource group and the region of the target instance.
  3. In the left-side navigation pane, click Sharded Cluster Instances.
  4. Find the target instance and click its ID.
  5. In the left-side navigation pane, click Database Connection to obtain the endpoint of a mongos.
    Connection information
  6. Connect to the sharded cluster instance from your client or ECS instance that has the mongo shell installed.
    mongo --host <mongos_host> -u <username> -p --authenticationDatabase <database>
    • <mongos_host>: the endpoint of a mongos in the sharded cluster instance.
    • <username>: the database account of the ApsaraDB for MongoDB instance. The initial account is root. We recommend that you do not log on to a database as the root account in a production environment. You can create accounts and grant permissions to the accounts. For more information, see Manage user permissions on MongoDB databases.
    • <database>: the name of the authentication database to which the database account belongs. If the database account is root, enter admin. If you want to specify a database other than the authentication database, run the db.createUser() command to create an account and then use the account to connect to the database.


    mongo --host s-bp********** -u root -p --authenticationDatabase admin
  7. When Enter password: is displayed, enter the password of the database account and press Enter. If you forget the password of the root account, you can reset the password. For more information, see Set a password for a standalone ApsaraDB for MongoDB instance.
    Note The password you enter is not displayed.

Common connection scenarios

Related FAQ