MongoDB : Exporting JSON with mongoexport

This will export a JSON representation of the database. Note that as a rule – particularly for backing up or moving data – MongoDB recommends the “dump and restore” approach as BSON can contain more rich data than JSON. Nevertheless, mongoexport still has its uses, sometimes a JSON representation of the data is very useful – it’s what we’ve been using so far in the application development.

Basic output to console

Need to specify the name of the database –db and the collection –collection to export. Restoring dumped data with MongoRestore Inserts only, no updates Exporting JSON with mongoexport

Basic output to console

> mongoexport –db meantest –collection tech

Send to a file

> mongoexport –db meantest –collection tech –out MEAN/api/data/tech.json

Create as array

> mongoexport –db meantest –collection tech –out MEAN/api/data/tech.json –jsonArray

Make output pretty

> mongoexport –db meantest –collection tech –out MEAN/api/data/tech.json –jsonArray –pretty

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s