Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoDB mongoimport upsert

Tags:

mongodb

upsert

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?

like image 202
crayfish Avatar asked Feb 06 '11 17:02

crayfish


2 Answers

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
like image 106
Andy Triggs Avatar answered Nov 15 '22 08:11

Andy Triggs


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.

like image 39
jared Avatar answered Nov 15 '22 09:11

jared