mongoDB mongoimport 更新插入

发布于 2024-10-15 21:35:42 字数 817 浏览 6 评论 0原文

我正在尝试使用以下

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

温柔戏命师 2024-10-22 21:35:42

您的 mongoimport 命令缺少 --upsert 选项,该选项需要与 --upsertFields 结合使用。尝试:

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

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
静谧幽蓝 2024-10-22 21:35:42

添加 --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.

泼猴你往哪里跑 2024-10-22 21:35:42

我假设 CSV 文件中的数据必须用双引号引起来。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文