TL;DR : Updating element in array always results in first element updated and results differ based on property name of key used in find params
Playground : Mongo playground
I want to update an object in a array and I am using 2 of the object properties to find the object then using $set operator with array.$.updateProperty to update the object
Here is the working playground link of what I want to do:
But I cant reproduce the same when I change a single property name (both in database as well as find parameter) , from the above example I changed property foo to trackID but then only the first element in array is always updated
Playground link in tldr at top
It seems weird as I assumed the property name shouldn’t matter as long as it used the same in find params too and its not a keyword like _id
Please refer to the arrayFilters documentation for more information.
Also, the $arrayFilters is available since MongoDB version 3.6. If you are looking to use the above query, would recommend you to update to the required version.