I'm trying to import a csv into mongodb using the following command:
mongoimport --db users --collection contacts --file data.csv --headerline
The database exists but not the collection, I want to create it and use the first row of the csv as the field names. Why am I getting error:
error validating settings: must specify --fields, --fieldFile or --headerline to import this file type
I also would like to know:
- how to copy/import data from one collection into another (basically the syntax)
- how datatypes from csv are handled in mongodb when imported; do I need to specify datatypes for headers or will mongodb read it from csv types?
To solve this:
Either make sure the first line of your
data.csv
file has field names of the data to be parsed and then execute:Or
Define the list of field names that the values of csv would be parsed in using
--fields