You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This requirement comes from the following design: we needed a collection with a property composed of nested arrays of objects, acting as a sort of matrix (rows with the first level array, columns with the second level array). Something like this:
But most importantly, we needed to perform PATCH operations only on specific elements of the second level array.
According to the MongoDB documentation it seems to be possible to update a specific element of an array using the arrayFilters operator of the findOneAndUpdate method. However in the patchById method which calls the findOneAndUpdate method we are currently not supporting such parameter. Note that this should also be possible for bulk operations, see the updateMany on the MongoDB documentation. Thus we should also modify the patchMany method.
Please note that I'm not 100% sure that this arrayfilters operator is the only way to update a specific element of a nested array, maybe this is also possible with the document filter, the difference between the two are not clear to me yet. I think that this operator might be useful when we want to update all the nested array elements that matches some precise conditions (e.g. the array elements with a given property which is $gte a given value).
This requirement comes from the following design: we needed a collection with a property composed of nested arrays of objects, acting as a sort of matrix (rows with the first level array, columns with the second level array). Something like this:
But most importantly, we needed to perform PATCH operations only on specific elements of the second level array.
According to the MongoDB documentation it seems to be possible to update a specific element of an array using the
arrayFilters
operator of thefindOneAndUpdate
method. However in thepatchById
method which calls thefindOneAndUpdate
method we are currently not supporting such parameter. Note that this should also be possible for bulk operations, see the updateMany on the MongoDB documentation. Thus we should also modify thepatchMany
method.Please note that I'm not 100% sure that this
arrayfilters
operator is the only way to update a specific element of a nested array, maybe this is also possible with the document filter, the difference between the two are not clear to me yet. I think that this operator might be useful when we want to update all the nested array elements that matches some precise conditions (e.g. the array elements with a given property which is$gte
a given value).P.S. For further info, note that while updates using the positional operator are not possible in nested arrays, they should be possible using a filtered positional operator.
The text was updated successfully, but these errors were encountered: