[SERVER-16888] $ positional operator with $elemMatch doesn't work when multiple update critera supplied Created: 15/Jan/15  Updated: 26/Sep/17  Resolved: 16/Jan/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: David Hows Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: regression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-14662 Positional projection queries (and po... Closed
Operating System: ALL
Participants:
Case:

 Description   

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.



 Comments   
Comment by J Rassi [ 16/Jan/15 ]

I am resolving this ticket as a dup of SERVER-14662, as it is unspecified as to which array member is updated in this case. See my comment on that ticket for a summary of the issue and a proposal to change the semantics of the positional operator in support of this use case.

Generated at Thu Feb 08 03:42:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.