Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dump an entire MongoDB database as text/json?

Tags:

mongodb

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!

like image 459
Adam Monsen Avatar asked Oct 05 '12 23:10

Adam Monsen


1 Answers

Using mongodump and bsondump:

Step 1 Dump the entire database to BSON files:

 mongodump --db db1

Step 2 Convert each BSON file to JSON file:

for f in dump/db1/*.bson; do bsondump "$f" > "$f.json"; done

Hope it's helps!

like image 116
Moshe Simantov Avatar answered Sep 20 '22 14:09

Moshe Simantov