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