MongoDB Import/Export
|
Russ Bateman
22 January 2013
last update:
Note: Do not use mongoimport and mongoexport for full instance, production backups because they do not reliably capture data type information.
Whether you choose CSV or JSON output, both are importable back into MongoDB. The CSV output is much easier to edit by hand for any tweaks you want to do.
$ mongoexport -port 37017 -db accountmgrdb -collection partners -fieldFile partnerfields.txt --csv -out partners.csv $ mongoexport -port 37017 -db accountmgrdb -collection partners -fieldFile partnerfields.txt --jsonArray -out partners.json
_id created forgotten loggedin entitykey secretkey companyname companywebsite businesscontactname businesscontactemail businesscontactphone businesscontactmobile techcontactname techcontactemail techcontactphone techcontactmobile timezone partnerdata
_id,created,forgotten,loggedin,entitykey,secretkey,companyname,companywebsite,businesscontactname,businesscontactemail,business... ObjectID(000000000000000000000222),2013-01-09T17:30:35Z,false,false,"partnerx_key","partnerx_secretkey","PartnerX","www.partner... ObjectID(000000000000000000000333),2013-01-09T17:30:35Z,false,false,"partnery_key","partnery_secretkey","PartnerY","www.partner... ObjectID(000000000000000000000555),2013-01-09T17:30:35Z,false,false,"BUYTEAMKEY","50244abe0f2bf2306829b4bf","BUY Team",,"Jackie... ObjectID(100000000000000000000111),2013-01-09T17:30:35Z,false,false,"dmhHeGhWRUdUc0hMRkZwYWVENTJPcThXQWRaZ2FURVh2NzVmN1k1cGpFaE... ...
Note that the JSON file has only one line in it.
[{ "_id" : { "$oid" : "000000000000000000000222" }, "created" : { "$date" : 1357752635583 }, "forgotten" : false, "loggedin" : f... ...}]