gpt4 book ai didi

mongodb - 在 mongodb 上更新子文档时遇到问题

转载 作者:可可西里 更新时间:2023-11-01 09:58:14 26 4
gpt4 key购买 nike

假设我有一个集合allitems,其中每个文档的形式都是

{_id: "1", items: [{number: 1, main: "how are you?", sub:[{id:1, item: "does it change with the day?", score: 0},{id:2, item:"some other question", score: 0}]}]}

如何更新子项目的分数?

我试过了

 db.allitems.update({_id:"1"}, {$set:{'items.0.sub.0.score': 5}});

我收到这个错误:

error: {
"$err" : "Unsupported projection option: items.0.sub.0.score",
"code" : 13097
}

我该如何解决这个问题?

最佳答案

您需要使用 $set 而不是 set 和使用点符号的引号键。

db.allitems.update({_id:"1"}, {$set: {'items.0.sub.0.score': 5}})

关于mongodb - 在 mongodb 上更新子文档时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15170216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com