我有一个Mongo文档,其中包含一个元素数组。
我想重置
.handled
数组中所有对象的属性,其中
.profile
=XX。
文件格式如下:
{
"_id": ObjectId("4d2d8deff4e6c1d71fc29a07"),
"user_id": "714638ba-2e08-2168-2b99-00002f3d43c0",
"events": [{
"handled": 1,
"profile": 10,
"data": "....."
} {
"handled": 1,
"profile": 10,
"data": "....."
} {
"handled": 1,
"profile": 20,
"data": "....."
}
...
]
}
所以,我尝试了以下方法:
.update({"events.profile":10},{$set:{"events.$.handled":0}},false,true)
但是它只更新
第一
每个文档中匹配的数组元素。(这就是
$ - the positional operator
.)
如何更新
全部的
匹配的数组元素?