mongoDB mongoimport upsert

不打扰是莪最后的温柔 提交于 2019-12-06 05:04:54

问题


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
stack@overflow.com,stackoverflow
mongo@db.com,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
abc@sasa.com,abc
imported 0 objects
encountered 99398 errors

Where is the problem? How should i be doing it?


回答1:


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



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4915007/mongodb-mongoimport-upsert

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!