How to convert MongoDB archive file to JSON format?

mongodb, mongodump

Solution

mongoexport

I believe the only way is from the database, using `mongoexport`:

mongoexport --db yourdb -c yourCollection --out yourCollection.json

warning from mongo

Just take notice of the following (from their website):

WARNING

Avoid using mongoimport and mongoexport for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.

Problem

If I dump a database like so: ``` mongodump --archive=out.mdb ``` Is there some way to convert `out.mdb` to a flat JSON file? If so, how? (for example, if I just wanted to restore a single document)

Original source