tencent cloud

TencentDB for MongoDB

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Strengths
Use Cases
Cluster Architecture
Product Specifications
Features
Regions and AZs
Terms
Service Regions and Service Providers
Purchase Guide
Billing Overview
MongoDB Pricing
Billing Formula
Payment Overdue
Backup Space Billing
Configuration Adjustment Billing
Getting Started
Quickly Creating an Instance
Connecting to a TencentDB for MongoDB Instance
Reading/Writing Database
Operation Guide
Access Management
Instance Management
Node Management
Version Upgrade
Network Configuration
Monitoring
Backup and Rollback
Database Audit
Data Security
SSL Authentication
Log Management
Database Management
Multi-AZ Deployment
Disaster Recovery/Read-Only Instances
Parameter Configuration
Recycle Bin
Task Management
Performance Optimization
Data Migration Guide
Practical Tutorial
Optimizing Indexes to Break Through Read/Write Performance Bottlenecks
Troubleshooting Mongos Load Imbalance in Sharded Cluster
Considerations for Using Shard Clusters
Sample of Reading and Writing Data in MongoDB Instance
Methods for Importing and Exporting Data Based on CVM Connected with MongoDB
What to Do for Errors of Repeated Instance Creation and Deletion of Databases with the Same Names?
Troubleshooting MongoDB Connection Failures
Shard Removal Task: Guide for Confirming the Progress and Troubleshooting Issues
Performance Fine-Tuning
Ops and Development Guide
Development Specifications
Command Support in Sharded Cluster v3.2
Command Support in v3.6
Development Ops
Troubleshooting
Increased Slow Queries
Number of Connections Exceeding Limit
API Documentation
History
Introduction
API Category
Making API Requests
Instance APIs
Backup APIs
Account APIs
Other APIs
Task APIs
Introduction
Data Types
Error Codes
Instance Connection
Shell Connection Sample
PHP Connection Sample
Node.js Connection Sample
Java Connection Sample
Python Connection Sample
Python Read/Write Sample
Go Connection Sample
PHP Reconnection Sample
Product Performance
Test Environment
Test Method
Test Result
FAQs
Cost
Features
Sharded Cluster
Instance
Rollback and Backup
Connection
Data Migration
Others
Service Agreement
Service Level Agreement
Terms of Service
Glossary
Contact Us

Shell Connection Sample

PDF
Focus Mode
Font Size
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.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback