Shell Connection Sample

Last updated: 2020-04-16 16:22:46

    You can use the MongoDB shell client (please see the installation documentation) on a CVM instance to connect to TencentDB for MongoDB for data management. Be sure to use the latest version of MongoDB client suite.

    Quick start

    A typical connection command is as follows:

    mongo 10.66.187.127:27017/admin -u mongouser -p thepasswordA1

    See the figure below:

    Connection in different authentication methods

    As described in the Connection Sample, TencentDB for MongoDB provides two usernames rwuser and mongouser by default to support the MONGODB-CR and SCRAM-SHA-1 authentication methods, respectively.
    For those two authentication methods, the shell parameters are not the same. See below for more information.

    SCRAM-SHA-1 authentication (mongouser)

    SCRAM-SHA-1 authentication is used for the default user mongouser and all new users created in the console. Shell connection parameters are the same as those described in Quick Start without additional parameters required. See the example below:

    mongo 10.66.187.127:27017/admin -u mongouser -p thepasswordA1

    If you want to enter a specific db directly such as "singer", after connecting to MongoDB, proceed as described below:

    mongo 10.66.187.127:27017/singer -u mongouser -p thepasswordA1 --authenticationDatabase admin

    See the figure below:

    MONGODB-CR authentication (rwuser)

    Please note that MONGODB-CR authentication is used only for the default user rwuser, and the authentication method of MONGODB-CR should be expressly specified in the shell connection parameters. See the example below:

    mongo 10.66.187.127:27017/admin -u rwuser -p thepasswordA1 --authenticationMechanism=MONGODB-CR

    See the figure below:

    If you want to enter a specific db directly such as "singer", after connecting to MongoDB, proceed as described below:

    mongo 10.66.187.127:27017/singer -u rwuser -p thepasswordA1 --authenticationMechanism=MONGODB-CR --authenticationDatabase admin

    See the figure below:

    Using shell to import and export data

    For both authentication methods, you can use the shell to import and export data. For more information, please see Export and Import.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help