0

Tried to import from csv data. Separated with ";".

Data example: CSV:

title; new title; one, two, three; some data, data, more data
title2; new title2; one2, two2, three2; some data2, data, more data

The import command line is:

mongoimport --db db_name --collection the_collection --type csv --file CSV_FILE.csv --fields field1, field2, field3

What am I doing wrong?

RaShe
  • 1,851
  • 3
  • 28
  • 42

2 Answers2

2

Lose the white space between the field names and you should be good:

mongoimport --db db_name --collection the_collection --type csv 
            --file CSV_FILE.csv --fields field1,field2,field3
mnemosyn
  • 45,391
  • 6
  • 76
  • 82
  • Well, it imports, but all is messed up. The csv data separated with ";", but in mongodb it's separates with "," – RaShe Nov 05 '14 at 19:32
1

RaShe - first, I agree with the previous answer posted.

You may also find this post useful: https://stackoverflow.com/a/17265858/3993224

For whatever reason, if you are using certain file types, importing as a '.csv' vs. as a Windows comma-separated file are not exactly the same thing. I used this approach to import values with commas within the text, and it imported them correctly (i.e. as single key/value pairs, rather than multiple key/value pairs any time a comma was found).

To do this:

  • Open the .csv you are trying to import
  • Save it as a Windows Comma Separated (.csv) file
  • Re-import it into MongoDB

Hope this helps.

Community
  • 1
  • 1