Wednesday, 11 September 2019

What is difference between Mongoexport and Mongodump

What is difference between Mongoexport and Mongodump

Question: What is mongodump ?
mongodump is a utility for creating a binary export of the contents of a database. mongodump is used for full backup, partial backup, syncing from production to staging/development, and changing the storage engine.




Question: What are popular options available with mongodump?
--help for Help
--version Version of mongodb
--host Host of database
--version Version of mongodump
--port Specify the port
--username Specify the username
--password Specify the password
--db Specify the database name
--collection Specify the collection name
--query Specify the query
--queryFile Specify the queryFile name
--gzip Compress the output
--out Specify the output folder
--repair Repair the database name



Question: Give few example of mongodump
Run Below command from Administrator window
Backup of all database?
 mongodump 

Backup of Single database?
 mongodump --db bank

Backup of collection?
mongodump --db bank --collection users

How to repair the mongoDB?
mongod --dbpath  "c:/data/db" --repair



Question: What is mongoexport?
mongoexport is used to export the collections data to a JSON or CSV format.


Question: How to export collection using mongoexport?
mongoexport --db bank --collection users --out D:\mm\users.json



Question: How to export collection fields using mongoexport?
mongoexport --db bank --collection users --fields "age,gender,email" --out D:\mm\users_e.json



Question: How to export collection data on behalf of query?
mongoexport --db bank --collection users --query "{'age':'female'}" --out D:\mm\users_e.json