Technology Encyclopedia Home >How to connect to Tencent Cloud MongoDB in shell?

How to connect to Tencent Cloud MongoDB in shell?

To connect to Tencent Cloud MongoDB in the shell, follow these steps:

  1. Install MongoDB Shell (mongosh)
    Ensure you have the MongoDB shell installed. Download it from the official MongoDB website if not already installed.

  2. Get Connection Details
    Retrieve the connection string from the Tencent Cloud MongoDB console:

    • Log in to the Tencent Cloud MongoDB console.
    • Select your instance and navigate to the Connection Information section.
    • Note the Connection String (e.g., mongodb://<username>:<password>@<host>:<port>/).
  3. Connect via Shell
    Use the mongosh command with the connection string:

    mongosh "mongodb://<username>:<password>@<host>:<port>/"
    

    Replace <username>, <password>, <host>, and <port> with your actual credentials.

    Example:

    mongosh "mongodb://admin:MyPassword123@cmgo-xxxxxx.mongodb.tencentcloudmongodbid.mongodb.rds.tencentcloud.com:27017/"
    
  4. Verify Connection
    If successful, you’ll see the MongoDB shell prompt (test>), indicating a successful connection.

Tencent Cloud Recommendation:
For enhanced security, use VPC peering or SSH tunneling if your instance is in a private network. Tencent Cloud MongoDB supports SSL encryption—enable it in the console and add --ssl to the mongosh command if required.

Example with SSL:

mongosh --ssl "mongodb://<username>:<password>@<host>:<port>/"