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
DocumentationTencentDB for MongoDBPractical TutorialMethods for Importing and Exporting Data Based on CVM Connected with MongoDB

Methods for Importing and Exporting Data Based on CVM Connected with MongoDB

PDF
Focus Mode
Font Size
Last updated: 2024-05-07 10:11:25
You can use a CVM instance to connect to TencentDB for MongoDB for data import and export. Be sure to use the latest MongoDB client suite. For detailed directions, see Connecting to TencentDB for MongoDB Instance.
Note:
The local database mainly stores metadata such as configuration information of the replica set and oplog, and the admin database mainly stores information such as users and roles. In order to prevent data disorder and authentication failures, TencentDB for MongoDB prohibits importing local and admin databases into an instance.

Export and Import Commands

MongoDB provides two sets of official tools for data import and export:
mongodump and mongorestore
mongoexport and mongoimport

mongodump and mongorestore

mongodump and mongorestore are generally used to export and import an entire database, as they manipulate data in BSON format, which is more efficient when a large number of dump and restore operations are performed.
The export command for mongodump is as follows:
mongodump --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb -o /data/dump_testdb
If the following information is output, the command is executed successfully:

The import command for mongorestore is as follows:
mongorestore --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --dir=/data/dump_testdb
If the following information is output, the command is executed successfully:


mongoexport and mongoimport

mongoexport and mongoimport are generally used to export and import a single set, as they manipulate data in JSON format, which features a higher readability.
The export command for mongoexport is as follows:
mongoexport --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb --collection=testcollection -o /data/export_testdb_testcollection.json
In addition, you can also include the -f parameter to specify a desired field or the -q parameter to specify a query condition so as to restrict the data to be exported.
The import command for mongoimport is as follows:
mongoimport --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb --collection=testcollection2 --file=/data/export_testdb_testcollection.json

Authentication Methods and Parameters

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 mongouser and all new users created in the console, follow the above directions to use the import and export tools.
For rwuser, the parameter --authenticationMechanism=MONGODB-CR should be included in each command.
Sample for mongodump:
mongodump --host 10.66.187.127:27017 -u rwuser -p thepasswordA1 --authenticationDatabase=admin --authenticationMechanism=MONGODB-CR --db=testdb -o /data/dump_testdb

Help and Support

Was this page helpful?

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

Feedback