Lets say there is an object like this in the db:
{
_id: <...>,
arrayOfObjects: [
{
criteria: "one",
value: 5
},
{
criteria: "two",
value: 5
},
{
criteria: "three",
value: 5
},
{
criteria: "four",
value: 5
},
]
}
What I want to do is to run an update similar to:
{
$inc: {
"arrayOfObjects.2.value" : -1
}
}
However I need it to affect only certain elements, e.g. {$or: [{criteria: "one"}, {criteria: "three"}]} I cannot rely on array indexes as the object copy I have may have expired before the update is executed (objects can be inserted, deleted, rearranged in the array).
Is it possible to pull this off? What would be the optimal way to do this?