tencent cloud

Feedback

Shell Connection Sample

Last updated: 2024-01-15 14:49:55
    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
    Note:
    To access TencentDB for MongoDB via a connection string, special characters in the password need to be converted to URL encoded characters so that they can be correctly identified. For example, "@" should be converted to "%40".
    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.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support