MongoDB database is also inseparable from the necessary maintenance, such as backup, recovery, import, export.
In fact, backup and recovery is easier than import and export, and generally does not make mistakes, so most of the time using backup and recovery operations.
1. Back Up MongoDB
Mongodump-h ruiyip-d Dataname-o/home/aa/dev/mongodb/data
Mongodump MONGO Export Database command Mongodump--HELP can see all the help under the command
-H Export Source
-d database name to export
The location to export the-o database
After the terminal rolls over n rows, the database export is completed, you can go to the/home/aa/dev/mongodb/data directory to view the exported files, Bson format (I export did not immediately see the file, waited for a while to appear, unexplained)
2. Restore using: Mongorestore command
Mongorestore-d Cmsdev/home/xx/dev/mongodb/data/cmsdev
-d database name used
Add directly to the directory you just exported, so that all tables are restored directly
If-C is the recovery of a table
3. Import
mongoimport-d my_mongodb-c User User.dat
Parameter description:
-d indicates which library to use, in this case "My_mongodb"
-C indicates the table to be exported, in this case "user"
You can see that the table structure is created implicitly when importing data
4. Export
mongoexport-d my_mongodb-c User-o User.dat
Parameter description:
-d indicates which library to use, in this case "My_mongodb"
-C indicates the table to be exported, in this case "user"
-O indicates the name of the file to be exported, in this case "User.dat"
From the above you can see how the export is using the JSON style
MongoDB Import Export Backup restore