MongoDB data export, import, and index creation

Source: Internet
Author: User
Tags mongodump mongorestore

MongoDB Data export, import, and index creation

(1) Data Export-one file per table:

# Mongoexport--db Project--collection table name--out output file name, such as:

# Mongoexport--DB Project--collectionstock--out Stock.json, export all F10 data to file/root/stock.json

(2) Data import-one file per table:

# mongoimport--db users--collection table name--file Enter file name

(3) Data backup:

A table:

# Mongodump--db Project--collection table name--out destination Path

Entire library:

# mongodump--db project--out Destination Path

A backup folder named after the database name is generated in the destination path, and the default backup path is in the dump directory of the user's home folder

(4) Data recovery:

A table:

# Mongorestore--db Project--collection table name Backup path

The backup path requires a. bson file that points to a table, such as: #mongorestore--db project--collection News_cjyw/.../dump/project/news_cjyw.bson

Entire library:

# Mongorestore--DB Project Backup path

The backup path needs to point to a folder with the database name, such as:

# Mongorestore--DB Project/.../.../dump/project

The corresponding. bson file in the backup path and the. metadata file need to exist simultaneously

(5) Indexing: (Restore data in Dump/restore mode without re-indexing, Export/import method requires re-indexing)

Enter the database:

# MONGO

>use Project

>db.stock.ensureindex ({"Stock code": 1, "Lastchange":-1})//This index must be built, the order of two parameters can not be wrong

>exit

MongoDB data export, import, and index creation

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.