2

假设我有一个集合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
}

我怎样才能解决这个问题?

4

1 回答 1

6

您需要使用$set代替set并引用使用点表示法的键。

db.allitems.update({_id:"1"}, {$set: {'items.0.sub.0.score': 5}})
于 2013-03-02T04:18:55.357 回答