MongoDB Import and export and database backup

Source: Internet
Author: User
Tags mongodb server first row mongodump mongorestore

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:  &nbsp ;        -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

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.