I'm trying to re mongoimport a CSV, but fails

284 views
Skip to first unread message

MKN Web Solutions

unread,
Sep 11, 2012, 4:56:20 PM9/11/12
to mongod...@googlegroups.com
I'm trying to mongoimport a csv, I'm using the correct commands, not sure what's going on but it might be something simple I missed.

mongoimport --db data --collection cities --type csv --file csv.csv -f city,country,p,state

This data came from a mongoexport / csv type; so I figured it'd read it back pretty straight forward... but it's only inserting 1 document with every thing as a value (while the key is {fieldX}) [x rep value++].


csv.csv

Wes Freeman

unread,
Sep 11, 2012, 5:02:51 PM9/11/12
to mongod...@googlegroups.com
It works for me. You probably want to use "--headerline" to avoid importing the first line, but either way I get 79 or 80 records imported.

Are you running some weird OS like Windows? Maybe you need to redo the line endings for it to work there...

Wes



--
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

MKN Web Solutions

unread,
Sep 11, 2012, 5:08:17 PM9/11/12
to mongod...@googlegroups.com
That's really weird.  I tried with headerline, but it returns 0 results instead of the 1. I'm running the latest version of MongoDB alongside CentOS.  

Could you export and attach that table back as a default or json file for me so I can inject back into my db.

Wes Freeman

unread,
Sep 11, 2012, 5:19:16 PM9/11/12
to mongod...@googlegroups.com
Interesting--it works fine on my mac (2.2.0). Here's the JSON... hope it works.

I used the following commands:
mongoimport --db data --collection cities --type csv --file csv.csv -f city,country,p,state --headerline
mongoexport -d data -c cities -o json.json

I tested it on one of my servers (CentOS with 2.0.4; I know, slightly old), and it got 80 results, even with --headerline--I suppose that is a new feature, but it worked better than your description.

Wes
json.json

MKN Web Solutions

unread,
Sep 11, 2012, 5:25:07 PM9/11/12
to mongod...@googlegroups.com
Thanks Wes.

To test, I saved the file a TSV and was able to import that.  Not too sure why CSV still didn't go through.
Reply all
Reply to author
Forward
0 new messages