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

v2.6.0-rc0 update $pop - changed behaviour + removes incorrect data

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-rc0
    • Fix Version/s: 2.6.0-rc2
    • Component/s: Write Ops
    • Labels:
      None
    • Backwards Compatibility:
      Major Change
    • Operating System:
      ALL

      Description

      The steps:

      Step 1.
      Add an object {_id : 1, a : [1, 2]} to the empty collection test:

      > db.test.drop()
      > db.test.insert({_id : 1, a : [1, 2]})

      Step 2.
      Let's try to pop from a[-2], i.e. from non existent data. This is nonsense perhaps but it changed behaviour.

      > db.test.update({_id : 1}, {$pop : {"a.-2" : 1}})
      WriteResult({
              "nMatched" : 0,
              "nUpserted" : 0,
              "nModified" : 0,
              "writeError" : {
                      "code" : 16837,
                      "errmsg" : "cannot use the part (a of a.-2) to traverse the element ({a: [ 1.0, 2.0 ]})"
              }
      })

      The above pop fails and data are not changed. In v2.4.9 this nonsense pop was silently ignored (if I am not mistaken).

      Step 3.
      Now let's pop from a[3], i.e. also from non existent data.

      > db.test.update({_id : 1}, {$pop : {"a.3" : 1}})
      WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
       
      > db.test.find()
      { "_id" : 1, "a" : [ 1 ] }

      The result is presumably incorrect. {$pop : {"a.3" : 1}} instead of failing (like with a.-2 in v2.6) or doing nothing (like with the same case in v2.4.9) it removes data from 'a' itself, i.e. actually performs another operation: {$pop : {"a" : 1}}.

        Attachments

          Activity

            People

            Assignee:
            scotthernandez Scott Hernandez
            Reporter:
            nightroman Roman Kuzmin
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: