mongoimport and csv with text delimiter

1,281 views
Skip to first unread message

Phil Wills

unread,
Jul 9, 2010, 12:50:35 PM7/9/10
to mongodb-user
I'm currently trying to import a csv into mongodb and hitting a rather
nasty hurdle. This csv includes some fields which can span multiple
lines of text. These are all surrounded by double-quote text
delimiters, which OpenOffice for instance understand fine, but
mongoimport starts a new element for each newline, even when they're
within the quotes. I can't find anything with --help to specify a
delimiter. Is there a way to achieve this?

To give a concrete example, given the file multiline.csv which
contains:

first-field, second-field, third-field
"First field","Second field first line
Second field second line","Third field"

then when I run

mongoimport -d multiline -c test --type csv --file multiline.csv --
headerline --drop --ignoreBlanks

then I end up with:

{ "_id" : ObjectId("4c37522653a73e76eb45b21d"), "first-field" : "First
field", "second-field" : "Second field first line" }
{ "_id" : ObjectId("4c37522653a73e76eb45b21e"), "first-field" :
"Second field second line\"", "second-field" : "Third field" }

whereas I would hope for:

{ "_id" : ObjectId("4c37522653a73e76eb45b21d"), "first-field" : "First
field", "second-field" : "Second field first line
Second field second line", "third-field": "Third field"}

Thanks,

Phil Wills

roger

unread,
Jul 10, 2010, 12:23:06 AM7/10/10
to mongodb-user
It looks like this is not supported, I can reproduce this here as
well. Is there a
way for you to avoid generating the multilne records ?

-Roger

Philip Wills

unread,
Jul 12, 2010, 7:19:09 AM7/12/10
to mongod...@googlegroups.com
Unfortunately I don't have access to the original data, only the csv
and the newlines are actually semantically important, so I wouldn't
really want to make them disappear.

However, I'm sure I can work round the issue by other means, just
wanted to check whether I was missing something.

Thanks for your time,

Phil

> --
> 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.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Michael Dirolf

unread,
Jul 12, 2010, 9:52:16 AM7/12/10
to mongod...@googlegroups.com
You can file a feature request on jira if it's something you'd like to
see supported.
Reply all
Reply to author
Forward
0 new messages