MongoDB Learning Note 07--Data backup, recovery

Source: Internet
Author: User
Tags mongodump mongorestore

    • Mongoexport export JSON or CSV format
    • Mongoimport Import JSON or CSV
    • Mongodump Export binary Bson structure data and index information
    • Mongorestore Importing binary files

Mongoexport

-h 主机--port 端口号-u 用户名-p 密码-d 库名-c 表名-f field1,field..... 导出的字段-q 查询条件 -o 导出文件名--csv 等同于 --type=csv 导出csv格式,一定要指定-f 导出字段才能导出csv

Example: Export the my_id<200 _id and username in the My table in the test database to CSV format

 mongoexport -u test -p 64823723zk -d test -c my -q {my_id:{‘$lt‘:200}} --type=csv -f _id,username,a -o my.csv

Mongoimport

-d 导入的数据库-c 导入的表--type csv/json--file 文件路径

Example: Importing data from a Stu.json into a Stu table in the test database

 mongoimport -u test -p 123 -d test -c stu --type json --file ./stu.json

Mongodump

-d 库名-c 表名-o 导出路径-f field1,field..... 字段名

Example: Export the My table of the test database with binary Bson structure data and index information to the dump directory
./mongodump-u test-p 123-d test-c my-o./dump

Mongorestore

-d 数据库--dir=  bson跟索引信息存放的目录

Example:

mongorestore -u test -p 123 -d test --dir=./dump/test/

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MongoDB Learning Note 07--Data backup, recovery

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.