My answer is very similar @Anthony but
a two extra parameter( for upsert
and multi
) are added. For reference You can check official document.
db.stocks.update(
{ "History": { "$elemMatch": { "status": { "$ne": "PROCESSED" } } } },
{ "$set": { "History.$[].flag": false }},
false, // show that if there is not any document with specified criteria , it will not create a new document.
ture // according to document of mongodb if multi is true then more than one document will be updated, other wise only one document will be updated.
)