"Go" mongodb Import and export and database backup

Source: Internet
Author: User
Tags mongodb server mongodump mongorestore

 -------------------MONGODB data import and Export-------------------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:           -D: Database name         &N Bsp  -c:collection name            --TYPE: Imported format default json          &NBS P -F: Imported field names            --headerline: If the imported format is CSV, you can use the header of the first row as the imported field       &NBS P    --file: Files to import      2, example:        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    &NBSP ;   parameter Description:           -H:MONGDB server address, for example: 127.0.0.1, you can also specify the port number:127.0.0.1:27017  & nbsp        -D: Database instances that need to be backed up, such as:test           -o: Data storage location for backup, for example:/home/mongodu mp/, of course, the directory needs to be established in advance, this directory contains the dataThe backup data for the library instance.     2, example:        sudo rm-rf/home/momgodump/        sudo mkdir-p/home /momgodump        sudo mongodump-h 192.168.17.129:27017-d itcast-o/home/mongodump/    &N Bsp  -2, MongoDB database recovery     1, Syntax:        mongorestore-h dbhost-d dbname--dir dbdirectory&nb sp;        parameter or name:           -H:MONGODB server address       &NBSP ;     D: db instance that needs to be recovered, such as test, which can also be different from the time of backup, such as test2           --dir: Where the backup data resides , 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/

Goto MongoDB Import Export and database backup

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.