-
Type: Bug
-
Resolution: Duplicate
-
Priority: Critical - P2
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
ALL
-
(copied to CRM)
Consider:
db.test.insert({array1: ["a", "b"], array2:[{_id:1}, {_id:2}]})
Update with elemMatch:
db.test.update({array1: "a", array2:{$elemMatch:{_id:2}}}, {$set {"array2.$.flag":"THIS ELEMENT WAS UPDATED"}});
Under 2.4
{ "_id" : ObjectId("54b84eb0d9f8df727c34dda5"), "array1" : [ "a", "b" ], "array2" : [ { "_id" : 1 }, { "_id" : 2, "flag" : "THIS ELEMENT WAS UPDATED" } ] }
Under 2.8.0-RC4 and 2.6.6
{ "_id" : ObjectId("54b84dfa0ed2d2cc8aa29721"), "array1" : [ "a", "b" ], "array2" : [ { "_id" : 1, "flag" : "THIS ELEMENT WAS UPDATED" }, { "_id" : 2 } ] }
Note how the wrong array member is updated in the 2.6/2.8 case.
- related to
-
SERVER-14662 Positional projection queries (and positional update ops) should fail with error if multiple arrays encountered
- Closed