Windows 10 Home Chinese version, MongoDB 3.6.3,
Objective
In the previous tests, some data had been written to the MongoDB database. Now to re-test the program, the old data in the database needs to be cleaned up, but you want to save the previously written data, so you need to export the data (or backup)-using the mongoexport command provided by MongoDB. By the way, the reverse operation of the export operation is tested--import the data and use the mongoimport command.
Note that the MongoDB Bin directory has been added to the Windows environment variable path.
So, how do two commands work? Use the command + --help parameter : You can view more detailed information in the links in the Help information
Mongoexport Frustration:
http://docs.mongodb.org/manual/reference/program/mongoexport/
Mongoimport Frustration:
http://docs.mongodb.org/manual/reference/program/mongoimport/
Operation
Action 1: Export data
Export the data under Authentication database globalnews to the file 0713_news_bck.json in the current directory.
In addition, the Mongoexport command can also be manipulated using the /uri option , which can be manipulated against the use of Help.
d:\ws\mdb_backup>Mongoexport/ u Reporter/ p 111111 /authenticationdatabase Globalnews/ D globalnews/news/ o 0713_news_bck.json
2018-07-13t16:36:31.977+0800 Connected To:localhost
2018-07-13t16:36:32.046+0800 exported 363 Records
Exported data file: The default is in JSON format, or it can be stored in CSV format or other (even customizable?). )
Description, Mongoexport exported data, just data, there is no database, collection-related information.
Action 2: Import data
Import the data from the external file 0713_news_bck.json (in the current directory) into the Foo collection under Database Globalnews.
The following command uses the /uri option , as well as the option to select Mongoexport above.
d:\ws\mdb_backup>mongoimport /uri "Mongodb://reporter:[email protected]:27017/globalnews? Authsource=globalnews "/ C foo /file 0713_news_bck.json
2018-07-13t16:55:27.558+0800 Connected To:localhost
2018-07-13t16:55:27.610+0800 Imported 363 Documents
Postscript
Data export can also use the Mongodump command, data recovery can use the Mongorestore command, has not been used, need to dig.
In any case, make sure your data is secure.
You will also try to back up your data on a regular basis.
You can also write a Web application to manage the MongoDB database.
Yes, the reporter user used in the above operation has the relevant permissions, otherwise, the operation fails.
Exporting and importing data using the MongoDB command tool