How to update multiple array elements in MongoDB?
Here is a snippet:
{
_id : ObjectId("587e2be4411f058ab566d7dc")
"body" : [
{
"hidden" : false,
"viewed" : {
"sub" : false,
"main" : false
}
},
"hidden" : false,
"viewed" : {
"sub" : false,
"main" : false
}
}
]
}
.update({_id : ObjectId("587e2be4411f058ab566d7dc")},{$set:{"body.$.viewed.main":true}},{multi : true});
This particular query always updates first matched element in the array.But i want to update all matched elements in array.