Reputation: 147
I'm trying to do a bulk update with the following
mongoimport -d my_db -c db_collection -upsertFields email ~/Desktop/update_list.csv
the csv that i'm trying to import looks like this.
email, full_name
[email protected],stackoverflow
[email protected],mongodb
It should check the email column as a query arg and update the full name accordingly. However, none were imported, it encountered errors.
exception:Failure parsing JSON string near: abc@sa
[email protected],abc
imported 0 objects
encountered 99398 errors
Where is the problem? How should i be doing it?
Upvotes: 6
Views: 12657
Reputation: 1305
Your mongoimport command is missing the --upsert option, which is needed in combination with --upsertFields. Try:
mongoimport -d my_db -c db_collection --upsert --upsertFields email ~/Desktop/update_list.csv
Upvotes: 16
Reputation: 1637
Add --type csv
Otherwise it assumes your input is json.
Also, looks like you should pass --headerline to make it use the first line of the file as a header.
Upvotes: 6
Reputation:
I assume that the data inside your CSV file must be double-quoted.
Upvotes: 0