mongoDB mongoimport 更新插入
我正在尝试使用以下
mongoimport -d my_db -c db_collection -upsertFields email ~/Desktop/update_list.csv
我尝试导入的 csv 进行批量更新,如下所示。
email, full_name
[email protected],stackoverflow
[email protected],mongodb
它应该检查电子邮件列作为查询参数并相应地更新全名。然而,没有导入,它遇到了错误。
exception:Failure parsing JSON string near: abc@sa
[email protected],abc
imported 0 objects
encountered 99398 errors
问题出在哪里?我应该怎样做呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的 mongoimport 命令缺少 --upsert 选项,该选项需要与 --upsertFields 结合使用。尝试:
Your mongoimport command is missing the --upsert option, which is needed in combination with --upsertFields. Try:
添加 --type csv
否则它假设您的输入是 json。
另外,看起来您应该传递 --headerline 以使其使用文件的第一行作为标题。
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.
我假设 CSV 文件中的数据必须用双引号引起来。
I assume that the data inside your CSV file must be double-quoted.