Shell Connection Sample

Last updated: 2019-08-12 11:34:00

PDF

In Tencent Cloud CVM, you can use the MongoDB shell client (see the Installation Documentation) to connect with TencentDB for MongoDB service for data management. Please 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

Authentication methods for the connections

As described in the Connection Example, By default, TencentDB for MongoDB provides two user names "rwuser" and "mongouser" for the "MONGODB-CR" and "SCRAM-SHA-1" authentication methods respectively.
Shell command parameters are different between these two authentication methods. See below for more information.

SCRAM-SHA-1 authentication (mongouser)

SCRAM-SHA-1 authentication is used by 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. See the example below:

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

Specifically, if you want to enter a "db" (“singer” in the example below) directly, after connecting with MongoDB, please proceed as described below:

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

MONGODB-CR authentication (rwuser)

Please note that MONGODB-CR authentication can be used only by the default user "rwuser", and the authentication method should be specified as MONGODB-CR in shell connection parameters. See the following example:

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


Specifically, if you want to enter a "db" (“singer” in the example below) directly after connecting to MongoDB, please proceed as described below:

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

Import and export data using shell

You can use Shell to import and export data both authentication methods described in this document. See Here.