我有一个Collection 像这样的东西
{
"_id" : ObjectId("5742be02289512cf98bf63e3"),
"name" : "test1",
"attributes" : [
{
"name" : "x",
"color" : "0xd79c9c",
"_id" : ObjectId("5742be02289512cf98bf63e8")
},
{
"name" : "y",
"color" : "0xd79c9c",
"_id" : ObjectId("5742be02289512cf98bf63e7")
},
{
"name" : "z",
"color" : "0xd79c9c",
"_id" : ObjectId("5742be02289512cf98bf63e6")
}
],
"__v" : 6
}
我想更新所有文档,并 for each 属性设置新字段.
db.spaces.update({}, { $set: { "attributes.0.weight": 2 } }, {multi: true})
但是当我运行这个查询时,我得到了一个错误:
"code" : 16837,
"errmsg" : "The positional operator did not find the match needed from the query. Unexpanded update: attributes.$.weight"
我不明白为什么.