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

XMLWordPrintableJSON

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

      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
              Reporter:
              David Hows (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: