MongoDB mongoimport upsert

I am trying to do a bulk update with the following

mongoimport -d my_db -c db_collection -upsertFields email ~/Desktop/update_list.csv 

The csv I'm trying to import is as follows.

 email, full_name stack@overflow.com ,stackoverflow mongo@db.com ,mongodb 

It should check the email column as a request argument and update the full name accordingly. However, none of them were imported; it encountered errors.

 exception:Failure parsing JSON string near: abc@sa abc@sasa.com ,abc imported 0 objects encountered 99398 errors 

Where is the problem? How am I supposed to do this?

+4
source share
3 answers

The mongoimport command does not have the -upsert option, which is required in conjunction with --upsertFields. Try:

 mongoimport -d my_db -c db_collection --upsert --upsertFields email ~/Desktop/update_list.csv 
+12
source

Add --type csv

Otherwise, it is assumed that your input is json.

Also, it looks like you should pass --headerline so that it uses the first line of the file as a header.

+6
source

I assume that the data inside your CSV file should be double.

0
source

Source: https://habr.com/ru/post/1338645/


All Articles