Please be aware that some answers in this thread suggesting use $[] is WRONG.
db.collection.update(
{"events.profile":10},
{$set:{"events.$[].handled":0}},
{multi:true}
)
The above code will update "handled" to 0 for all elements in "events" array, regardless of its "profile" value. The query {"events.profile":10}
is only to filter the whole document, not the documents in the array. In this situation it is a must to use $[elem]
with arrayFilters
to specify the condition of array items so Neil Lunn's answer is correct.