To connect to Tencent Cloud MongoDB in the shell, follow these steps:
Install MongoDB Shell (mongosh)
Ensure you have the MongoDB shell installed. Download it from the official MongoDB website if not already installed.
Get Connection Details
Retrieve the connection string from the Tencent Cloud MongoDB console:
mongodb://<username>:<password>@<host>:<port>/).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/"
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>/"