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

Data Migration

PDF
Focus Mode
Font Size
Last updated: 2025-04-14 14:22:42

How do I set parameters to export data from TencentDB for MongoDB?

In mongodump parameters, set --readPreference=secondaryPreferred.

What data migration types are supported in TencentDB for MongoDB?

Migration from CVM-based self-created and public network-based instances is supported. For more information, please see Migration Overview.

How do I export MongoDB data to my local device by using mongodump (for an entire database) or mongoexport (for a single collection)?

In CVM, you can use the MongoDB shell client to connect to TencentDB for MongoDB for data export. Please use the latest MongoDB client suite. MongoDB provides two sets of official tools for data export. Generally, mongodump is used to export an entire database, where the BSON data format is used to facilitate massive data dump, while mongoexport is used to export a single collection, where the JSON data format is used for higher readability. 1. Use mongodump to export an entire database for backup The export command is as follows:
mongodump --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb -o /data/dump_testdb

2. Use mongoexport to export a single collection for backup The export command 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
Note:
In addition, you can 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.
3. Parameters for export commands written by the users rwuser and mongouser As described in the Connection Sample, TencentDB for MongoDB provides two usernames rwuser and mongouser by default to support MONGODB-CR and SCRAM-SHA-1 authentication respectively.
For mongouser and all new users created in the console, simply follow the above samples to use the export tools.
For rwuser, the parameter --authenticationMechanism=MONGODB-CR should be included in each command.
mongodump sample:
mongodump --host 10.66.187.127:27017 -u rwuser -p thepasswordA1 --authenticationDatabase=admin --authenticationMechanism=MONGODB-CR --db=testdb -o /data/dump_testdb

How do I import local data into TencentDB for MongoDB by using mongorestore (for an entire database) or mongoimport (for a single collection)?

In CVM, you can use the MongoDB shell client to connect to TencentDB for MongoDB for data import. Please use the latest MongoDB client suite.
MongoDB provides two sets of official tools for data import. Generally, mongorestore is used to import an entire database, where the BSON data format is used to facilitate massive data mongorestore, while mongoimport is used to import a single collection, where the JSON data format is used for higher readability.
1. Use mongorestore to import an entire database for backup The import command is as follows:
mongorestore --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --dir=/data/dump_testdb

2. Use mongoimport to import a single collection for backup The import command 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
3. Parameters for import commands written by the users rwuser and mongouser As described in the Connection Sample, TencentDB for MongoDB provides two usernames rwuser and mongouser by default to support MONGODB-CR and SCRAM-SHA-1 authentication respectively.
For mongouser and all new users created in the console, simply follow the above samples to use the import tools.
For rwuser, the parameter --authenticationMechanism=MONGODB-CR should be included in each command.
mongorestore sample:
mongorestore --host 10.66.187.127:27017 -u rwuser -p thepasswordA1 --authenticationDatabase=admin --authenticationMechanism=MONGODB-CR --db=testdb -o /data/dump_testdb

Why does the data imported into TencentDB for MongoDB occupy less capacity than in self-created MongoDB?

Possible causes:
There are a large number of creation, deletion, and update operations accumulated after the database has been running for a long time.
MongoDB allocates a larger capacity than the actual data size during write operations in order to improve performance.
The original capacity is not reused after the data is deleted. All these result in an overall higher void rate in the entire database capacity. Meanwhile, importing data can be considered as an operation similar to disk defragging, which makes imported data more compact and appear smaller in size.

What should I do if mongodump is unable to export data from MongoDB?

For more information on how to use mongodump, please see Import and Export. You are recommended to use mongodump 3.2.10 or above.

Help and Support

Was this page helpful?

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

Feedback