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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 4.2.12
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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" });

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: