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

`$pull`ed index should not override query-matched index for `$(update)`

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.2.12
    • Component/s: Querying
    • None
    • ALL
    • Hide

      Run the following in a collection `testCol`.

      db.testCol.insertOne({
       _id: "TEST",
       toPull: ["A", "B", "C", "D", "E"],
       toSet: [
        {id: "E"},
        {id: "D"},
        {id: "C"},
        {id: "B"},
        {id: "A"},
       ]
      });
      
      db.testCol.updateOne({
       _id: "TEST",
       toPull: "B",
       toSet: {$elemMatch: {id: "B"}}
      }, {
       $set: { "toSet.$.data": "Z" },
       $pull: { toPull: "B" },
      });
      
      db.testCol.findOne({_id: "TEST"});
      
      Show
      Run the following in a collection `testCol`. db.testCol.insertOne({ _id: "TEST" , toPull: [ "A" , "B" , "C" , "D" , "E" ], toSet: [ {id: "E" }, {id: "D" }, {id: "C" }, {id: "B" }, {id: "A" }, ] }); db.testCol.updateOne({ _id: "TEST" , toPull: "B" , toSet: {$elemMatch: {id: "B" }} }, { $set: { "toSet.$.data" : "Z" }, $pull: { toPull: "B" }, }); db.testCol.findOne({_id: "TEST" });

      The index of `$pull`ed element in an unrelated field becomes `$(update)` when `$set`ting another field. See steps to reproduce. Expected result is to set `{data: "Z"}` on the forth element, but it actually set it on the second element, due to pulling the second element of another unrelated field.

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            wegylexy@gmail.com TimTIM Wong
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: