Double quote badly exported in mongoexport csv ?

1,616 views
Skip to first unread message

Thomas

unread,
Jul 26, 2012, 6:15:19 AM7/26/12
to mongod...@googlegroups.com
Hello,

I have some trouble while I'm trying to export a collection into a csv file.
Here is what my collection contains :
> db.tmp.find()
{ "_id" : ObjectId("501116de006358eb4e641b8e"), "val" : "titi\"toto" }

Here is the command line used to export my csv file
mongoexport -c tmp -d test -u user -p password --csv -f 'val' -o res.csv

And the content in res.csv :
val
"titi""toto"


Why a double quote contained in a string is exported into two double quotes ? Is it a way to protect char with " ?
Thank you,

Thomas.


PS : I'm using mongodb 2.06 under linux ubuntu 64bits




Sam Millman

unread,
Jul 26, 2012, 9:37:46 AM7/26/12
to mongod...@googlegroups.com
It is a form of escaping to use back slash.

I am not fluent with mongoimports coding however I would say it is because the importer cannot, from csv standards, understand from that string what is the end and what is the beginning so it attempts to guess.

Though I would say that if two "" are encountered and no comma is between them maybe it should not escape and assume that is the string entirely.





--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Sam Millman

unread,
Jul 26, 2012, 9:38:05 AM7/26/12
to mongod...@googlegroups.com
by mongiimport I mean mongoexport ofc

Sam Millman

unread,
Jul 26, 2012, 10:05:02 AM7/26/12
to mongod...@googlegroups.com
Oops just realised I read your question backwards, ignore my rambling

Stephen Steneker

unread,
Jul 28, 2012, 11:03:07 PM7/28/12
to mongod...@googlegroups.com
I have some trouble while I'm trying to export a collection into a csv file.
Here is what my collection contains :
> db.tmp.find()
{ "_id" : ObjectId("501116de006358eb4e641b8e"), "val" : "titi\"toto" }

Here is the command line used to export my csv file
mongoexport -c tmp -d test -u user -p password --csv -f 'val' -o res.csv

And the content in res.csv :
val
"titi""toto"


Why a double quote contained in a string is exported into two double quotes ? Is it a way to protect char with " ?

Hi Thomas,

This is expected formatting for CSV (Comma-Separated Value) files .. a double quote character in a string is indicated by two double quotes:

There's also an RFC describing the "standard" CSV format (though not all parsers will comply with this): http://tools.ietf.org/html/rfc4180.

Cheers,
Stephen
Reply all
Reply to author
Forward
0 new messages