MongoDB data import and export and data backup _mongodb

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

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:

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.