This article is reproduced to: https://www.cnblogs.com/qingtianyu2015/p/5968400.html
1. Export tool: Mongoexport 1, Concept: the Mongoexport tool in MongoDB can export a collection to a file in JSON format or CSV format. You can specify the exported data items through parameters, or you can export the data based on the criteria you specify. 2. Syntax: mongoexport-d dbname-c collectionname-o file--type json/csv-f field parameter description:-D: Database name -c:collection name-o: Output filename--type: output format, default to json-f: Output field, if-type is CSV, you need To add-F "field name" 3, Example:
2, Data import: Mongoimport 1, Syntax: mongoimport-d dbname-c collectionname--file filename--headerline--type -F Field Parameter description:-d: Database name-c:collection name--type: Imported format default json-f: Import Field name--headerline: If the imported format is CSV, you can use the header of the first row as the imported field--file: File 2 To import, example: sudo mongoimp ort-d mongotest-c users--file/home/mongodump/articles.json--type JSON
-------------------MongoDB Backup and Recovery-------------------1, MongoDB database backup 1, Syntax: Mongodump-h dbhost-d dbname-o dbdirectory parameter description: - H:MONGDB address of the server, for example: 127.0.0.1, of course, you can also specify the port number: 127.0.0.1:27017 -D: Database instances that need to be backed up, For example: Test -O: Backup data storage location, such as:/home/mongodump/, of course, the directory needs to be established in advance, this directory contains the database instance of the backup data. 2, example: sudo rm-rf/home/momgodump/ sudo mkdir-p/ho Me/momgodump sudo mongodump-h 192.168.17.129:27017-d itcast-o/home/mongodump/ &NBSP ; -2, MongoDB database recovery 1, Syntax: mongorestore-h dbhost-d dbname--dir Dbdi Rectory parameter or name: -H:MONGODB server address &NBSP ; -D: Database to be restoredExample: Test, of course, this name can also be different from the backup time, such as Test2 --DIR: Backup data location, for example:/home/mongodump/ itcast/ --drop: When recovering, first delete the current data, and then restore the backed-up data. That is, after the recovery, the data added modified after the backup will be deleted and used with caution. 2, Example: