I have an update statement that use to work in 2.2.6, but fails in 2.8.x and in 3.0.1
In short: I have an array of items, and I want to update the one with a name of 'CreateDeliveries' and a state of 'NOT STARTED'.
The problem is this just updates the first element in the array, not the one that matches (i.e. the last element).
In 2.2.6 this worked fine.
In 2.8.x this updates the first element (incorrect)
In 3.0.1 this updates zero rows.
This is my test document..
{
"_id" : ObjectId("5510070f7baa49e5db605c89"),
"cacheIds" : [
"456"
],
"expectedSteps" : [
{
"name" : "CacheBuildProcessor",
"state" : "ENDED"
},
{
"name" : "CacheProcessors",
"state" : "NOT STARTED"
},
{
"name" : "ProductSequential",
"state" : "NOT STARTED"
},
{
"name" : "PriceSequential",
"state" : "NOT STARTED"
},
{
"name" : "Data to CSV",
"state" : "NOT STARTED"
},
{
"name" : "CreateDeliveries",
"state" : "NOT STARTED"
}
]
}
note: cacheIds is also an array, this might be affecting it.
db.getCollection('TEST').update(
{
"cacheIds" : "456" ,
"expectedSteps" : {
"$elemMatch" :
{ "name" : "CreateDeliveries" , "state" : "NOT STARTED"}
}
},
{
$set: {"expectedSteps.$.state" : "ENDED"}
}
);
Now I've tried to use a projection to just return the section of the array I care about, and so just get it to update that section, but that doesn't seem to be a valid query/update command (it is a valid query).
Has anyone got any ideas?