Question

I seem to keep having this error when i try and import anything?

In terminal I input:

name:~ computer$ mongoimport --db users --collection contacts --type csv --file /Users/computer/Desktop/ftse100.csv
connected to: 127.0.0.1
assertion: 9998 you need to specify fields

I wouldn't know what to ask. I tried adding --field after this command line but just get help information.

ER

Was it helpful?

Solution

As per mongodb docs

 --fields <field1[,field2]>, -f

Specify a comma separated list of field names when importing csv or tsv files that do not have field names in the first (i.e. header) line of the file.

mongoimport --db users --collection contacts --type csv --file /Users/computer/Desktop/ftse100.csv --fields field1, field2,field3

As per your question, there is a typo it's not --field instead --fields

OTHER TIPS

In 2.4.6, mongoimport does not find the header in csv files that I make, with or without double quote boundaries.

If I chop off the header line and supply that same text to the -f or --fields option, it my files import fine.

If you want to add all columns, use --headerline option instead of -fields.

In your case it would be:

mongoimport --db users --collection contacts --type csv --headerline --file /Users/computer/Desktop/ftse100.csv
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top