Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert MongoDB archive file to JSON format?

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)

like image 491
ffxsam Avatar asked Oct 29 '16 01:10

ffxsam


People also ask

How do I export a MongoDB database to JSON?

mongoexport command is used to export MongoDB Collection data to a CSV or JSON file. By default, the mongoexport command connects to mongod instance running on the localhost port number 27017. Field_name(s) - Name of the Field (or multiple fields separated by comma (,) ) to be exported.

Is MongoDB in JSON format?

Anything you can represent in JSON can be natively stored in MongoDB, and retrieved just as easily in JSON. The following are some example documents (in JavaScript / Python style syntax) and their corresponding BSON representations.

Is MongoDB good for JSON?

If you want to modify your JSON data inside the data store, though, MongoDB will work better — it has tools for updating individual fields. To modify JSON fields in Postgres, on the other hand, you'd need to extract the whole document and then rewrite it back in when you've made your changes.

How do we use JSON in MongoDB?

Modeling embedded data With MongoDB, this problem can easily be solved by embedding data using JSON as it supports embedded files. It can embed related data and lists in the same document instead of creating a new table as shown below. We just structured our JSON data for use in MongoDB.


1 Answers

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.

like image 93
alexbt Avatar answered Sep 29 '22 02:09

alexbt