MongoDB data Backup, restore notes

Source: Internet
Author: User
Tags mongodump

Company database migration, so add a bit of knowledge:

1 Import and export of collections

Command-line help Mongoexport--help

Export

Export Newsserver database under News collection

mongoexport-d newsserver-c News-o D:\data\news.json

Same as above, but specify only partial fields (Id,title)

mongoexport-d newsserver-c news-f _id,title-o D:\data\news.json

If you need user rights authentication, you need to specify the user and password,-u (--user) followed by the set user name, the password set by-p

Mongoexport-u username-p pass-d newsserver-c news-o D:\test.json

Import (if authentication is required)

If it's a JSON file,

Mongoimport-u username-p pass-d newsserver-c News--file D:\test.json

If it is a CSV file (Specify a field, you can specify the field of the collection to be imported by--fileds (-f)

Mongoimport-u username-p pass-d newsserver-c news--type csv--fields _id,from_user_id--file d:\test.csv

2 Import and export of databases

Export

Export the Newsserver database

mongodump-d Newsserver-o/home/dbbackup

If there is a validation, you need to specify a username, password

Mongodump-u username-p pass-d Newsserver-o/home/dbbackup

Export, if verification is required

Mongorestore--port 27017-u username-password=pass--drop-d newsserver/home/dbbackup/newsserver

MongoDB data Backup, restore notes

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.