How can I dump an entire MongoDB database as text (plain text, json, or CSV)?
I’m using an application I’m not too familiar with. I’d like to
- clear the database
- load seed data
- dump the whole db as text
- do some stuff
- dump again
then diff the two!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
mongoexportutility. It will dump out json by default but you can specify to dump out csv format.mongoexport --helpwill give you all the options you will need.You mentioned that you would like to dump all the collections from a database, and
mongoexportexpects you to specify a database and collection name, since it expects to dump one collection.You can write a short shell script (if you are on Windows, convert to batch script) to the effect of: