Showing posts with label mongo. Show all posts
Showing posts with label mongo. Show all posts

Tuesday, October 20, 2015

taking mongo db dump and restore

Here is how you can take dump of  mongo collection in csv file.

 mongoexport -d -c -q '{query}' -f  field1,field2,field3,...,fieldn --csv -o
      e.g.
 mongoexport -d seo_metadata -c seo_product -q '{"create_date" : {"$lt":"2015-08-31"}}' -f create_date,update_date,object,meta_keyword,meta_title,meta_content --csv -o /var/tmp/outfile.csv

mongoimport restores a database from a backup taken with mongoexport.

 mongoimport --db --collection --type csv --file

mongoimport --db users --collection contacts --type csv --file contacts.csv
Mongo import/export can be done in json format too. for more information visit mongo documentation