Helllo @Philip_Enaohwo,
Welcome to the community! ![]()
I notice you haven’t had a response to this topic yet - were you able to find a solution?
If not, then you can try below.
db.collection.updateOne(
{"variants.items._id" : "62be0271d373b2f2fc1826a8"},
{$set: {
'variants.$[].items.$[xxx].quantity': 999
}},
{arrayFilters: [
{"xxx._id": '62be0271d373b2f2fc1826a8'}
]}
)
Your particular use case includes Array within an Array, below is the explanation of the query.
- db.collection.updateOne() : Updates a single document within the collection based on the filter.
- The $set operator replaces the value of a field with the specified value.
- The filtered positional operator
$[<identifier>]identifies the array elements that match thearrayFiltersconditions for an update operation. In the example above, it was used in conjunction with thearrayFiltersoption to update all elements that match thearrayFiltersconditions.
For more details, please see Update Nested Arrays in Conjunction with $[]
Let me know if you have any more questions. Happy to help! ![]()
Regards,
Tarun