On a CVM instance, you can use the MongoDB shell client to connect to TencentDB for MongoDB for data import and export. Please be sure to use the latest MongoDB client suite. For detailed directions, please see Access Connection > Connection Samples.
Note:
The
local
database mainly stores metadata such as configuration information of the replica set and oplog, and theadmin
database mainly stores information such as users and roles. In order to prevent data disorder and authentication failures, TencentDB for MongoDB prohibits importinglocal
andadmin
databases into an instance.
MongoDB provides two sets of official tools for data import and export:
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.
mongodump --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb -o /data/dump_testdb
mongorestore --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --dir=/data/dump_testdb
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.
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.mongoimport --host 10.66.187.127:27017 -u mongouser -p thepasswordA1 --authenticationDatabase=admin --db=testdb --collection=testcollection2 --file=/data/export_testdb_testcollection.json
As described in Access Connection > Connection Samples, TencentDB for MongoDB provides two usernames rwuser
and mongouser
by default to support the MONGODB-CR
and SCRAM-SHA-1
authentication methods, respectively.
mongouser
and all new users created in the console, simply follow the above samples to use the import and 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
Was this page helpful?