1. Export Tools:mongoexport 1, concept: The Mongoexport tool in MongoDB can export a collection to a file in JSON or CSV format. You can specify the exported data item by parameter, or you can export the data based on the specified criteria. 2, Syntax: mongoexport-d dbname-c collectionname-o file--type json/csv-f field&nb Sp parameter description: -D: Database name -C: Collection name -o: Output filename --type: output format, default For json -F: Output field, if-type is CSV, you need to add-f "field name" 3, example: sudo mongoexport-d mongotest-c users-o/home/python/desktop/mongodb/users.json--type json-f "_id,user_id , User_name,age,status " 2, data import:mongoimport 1, Syntax: mongoimport-d dbname-c CollectionName--file filename--headerline--type json/csv-f field parameter description: &NBsp -D: Database name -c:collection name & nbsp --type: Imported format default json -F: Imported field name --headerl INE: If the imported format is CSV, you can use the header of the first row as the imported field --file: File to import 2, Example: & nbsp sudo mongoimport-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 server location Address, for example: 127.0.0.1, you can also specify a port number:127.0.0.1:27017 -D: DB instance that needs to be backed up, such as:test -O: The data storage location of the backup, for example:/home/mongodump/, of course, the directory needs to be established in advance, this directory contains the database instance backup data. 2, example: SUDo rm-rf/home/momgodump/ sudo mkdir-p/home/momgodump sudo mongod Ump-h 192.168.17.129:27017-d itcast-o/home/mongodump/ 2, MongoDB database recovery 1, Syntax: &NB Sp mongorestore-h dbhost-d dbname--dir dbdirectory parameter or name:   ; -H:MONGODB server address -D: The database instance that needs to be restored, for example: test, and of course the name can be Different times, such as test2 --dir: Where to back up your data, such as:/home/mongodump/itcast/ --drop: When recovering, delete the current data and then restore the backed up data. That is, after the recovery, add the modified data after the backup will be deleted, use with caution! 2, instance: mongorestore-h 192.168.17.129:27017-d itcast_restore--dir/home/mongodump/itcast/
MongoDB Import Export and database backup