-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Labels:
----------------------------
Original Description
In the documentation of the $[<identifier>] operator, section Update All Array Elements that Match Multiple Conditions, it states:
To modify the value of the std field for all elements in the grades array where both the grade is greater than or equal to 80 and the std is greater than or equal to 5, use the positional $[<identifier>] operator and arrayFilters:
db.students.update( { }, { $inc: { "grades.$[elem].std" : -1 } }, { arrayFilters: [ { "elem.grade": { $gte: 80 }, "elem.std": { $gt: 5 } } ], multi: true } )
However, isn't that contradictory to what it is explained in the update operation documentation with regards to arrayFilter?:
You can include the same identifier multiple times in the update document; however, for each distinct identifier ($[identifier]) in the update document, you must specify exactly one corresponding array filter document. That is, you cannot specify multiple array filter documents for the same identifier. For example, if the update statement includes the identifier x (possibly multiple times), you cannot specify the following value for arrayFilters:
[ { "x.a": { $gt: 85} }, { "x.b": { $gt: 80 } } ]
----------------------------