Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-16888

$ positional operator with $elemMatch doesn't work when multiple update critera supplied

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • ALL

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            david.hows David Hows
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: