crayfish
crayfish

Reputation: 147

mongoDB mongoimport 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?

Upvotes: 6

Views: 12657

Answers (3)

Andy Triggs
Andy Triggs

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

jared
jared

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

user2665694
user2665694

Reputation:

I assume that the data inside your CSV file must be double-quoted.

Upvotes: 0

Related Questions