In mongodump parameters, set --readPreference=secondaryPreferred
.
Migration from CVM-based self-created and public network-based instances is supported. For more information, please see TencentDB for MongoDB Data Migration.
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
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.
mongouser
and all new users created in the console, simply follow the above samples to use the export tools.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
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.
mongouser
and all new users created in the console, simply follow the above samples to use the import tools.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
Possible causes:
For more information on how to use mongodump, please see Import and Export. You are recommended to use mongodump 3.2.10 or above.
Was this page helpful?