mongodb - Records with comma seperator are not exported correctly in mongo DB -
i using below command export contacts collection's fields f1 , f2 contacts.csv
mongoexport --db users --collection contacts --csv --out /opt/backups/contacts.csv --fields f1,f2
its working fine , data exported csv.
the problem f2 field's records export.
f2 field stored in db comma seperated values 1,samuel,it.
i think mongo exporting in csv , considering comma seperator.
so, 1 , samuel , ane exported 3 different cells in csv file below,
field1 field2 ==== ==== ====== == 1 1 samuel instead want follows field1 field2 ==== ==== 1 1,samuel,it
btw using mongo 1.6.5
mongodb 1.6.5 released in december, 2010 , lot has changed since then. worth upgrading @ least mongodb 2.2 if not 2.4.
if full upgrade of mongodb not option, try running mongoexport
mongodb 2.4 against current database. command line tools should backward compatible.
it looks mongoexport
csv formatting made more compliant release of mongodb 2.0 , changes server-1097 ("mongoimport / export should adhere csv spec"), there subsequent improvements or fixes.
i tried simple test mongodb 1.6.5 , mongoexport --csv
format seemed ok:
field1,field2 1,"1,samuel,it"
another possibility issue lies in application/tool trying use import csv. there several different interpretations "valid" csv formatted file should like. agrees csv contains fields separated commas, field escaping can vary.
Comments
Post a Comment