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

Connecting Through MongoDB Shell

PDF
フォーカスモード
フォントサイズ
最終更新日: 2025-11-26 10:09:09
This method is applicable to interactive command-line tools and is suitable for database management, querying, and data operations.

Step 1: Logging In and Installing MongoDB Shell

1. Log in to the Cloud Virtual Machine (CVM) console and connect to a CVM instance.
2. Download MongoDB Shell: Use the wget command to download MongoDB Shell, and then decompress the file. The following example uses MongoDB Shell (mongosh) 2.5.6.
Note:
When selecting a MongoDB Shell version, ensure it is compatible with your TencentDB for MongoDB service and the CVM operating system. For download details, see MongoDB Shell Download.
wget https://downloads.mongodb.com/compass/mongosh-2.5.6-linux-x64.tgz
tar zxvf mongosh-2.5.6-linux-x64.tgz

Step 2: Running the Connection Command

1. Go to the decompressed directory and run the following command to connect to the MongoDB instance.
./bin/mongosh -u mongouser -p ******** 10.1.0.44:27017/admin
-u: Specify the username. (For example, the default user mongouser.)
-p: Specify the password for the corresponding user.
host:port: Replace with the private network address and port of the MongoDB instance.
/admin: Specify admin as the authentication database.
2. Example for connecting to multiple nodes.
./bin/mongosh -u mongouser -p your_password 10.1.0.44:27017,10.1.0.31:27017/admin

Step 3: Verifying the Connection

After a successful connection, you will see a prompt similar to the following, which includes the versions of MongoDB and Mongosh.

Connecting to: mongodb://<credentials>@10.1.0.44:27017,10.1.0.31:27017/test?replicaSet=cmgo-2jkr****_0&authSource=admin&appName=mongosh+2.5.6
Using MongoDB: 7.0.12
Using Mongosh: 2.5.6

Step 4: Reading and Writing to Databases

For specific operation examples about creating and managing databases, see Reading and Writing to Databases.

ヘルプとサポート

この記事はお役に立ちましたか?

フィードバック