Search code examples
mongodbmongoexport

How to remove delimiter from data in mongoexport


I am executing this query to get data in comma separated file

mongoexport --host <IP> --db <database> --collection <collection> --type csv --fields _id,contactNo,longitude,latitude,city,state,locality,pinCode -q '{"updatedAt": {$gt: ISODate("2017-09-27T00:00:00.000Z")}}' --limit 5 --out data_sample.json

However the data itself contains commas. How do I remove comma from the data before writing it to file? If I use some other delimiter, then also there will always be a risk that it could come in the data. So, I want to replace all comma with blank and then load data to file.


Solution

  • The csv output of mongoexport encloses all those fields which have delimiter in data itself with double quotes. The csv can be loaded in Excel or any MySQL table by providing appropriate options of enclosed by '"'