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

Unexpected matching behaviour for current $pull with $elemMatch syntax

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: 1.6.3
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      All
    • Backwards Compatibility:
      Major Change

      Description

      Currently the syntax for the $pull operand is confusing and conflicts with normal behaviour of $elemMatch.

      Given document :

      {"somearray" : [

      { "a" : 1, "b" : 1, "c" : 1 }

      ,

      { "a" : 1, "b" : 1 }

      ,

      { "a" : 1 }

      ] }

      The current and expected behaviour of using $elemMatch or omitting it for an update to pull out an element is as follows :

      UPDATE: db.test.update({}, {$pull : {somearray : {$elemMatch : {a:1, b:1}}}})
      EXPECTED BEHAVIOUR : partial match on first item, so pull that
      CURRENT BEHAVIOUR : has no effect

      UPDATE: db.test.update({}, {$pull : {somearray :

      {a:1, b:1}

      }})
      EXPECTED BEHAVIOUR : exact match on second item, so pull that
      CURRENT BEHAVIOUR : removes item 1 and 2, so it's partial matching which is the usage pattern for the $elemMatch case

      The end result is both behaviour that's less than intuitive and presents the problem i'm currently facing with our migration to mongo : How do I remove just the second item with exact/full document matching?

      If this isn't a bug the $elemMatch example should be removed from the docs and the docs itself should elaborate on $pull only supporting partial matching. If it is a bug however it does present the problem if it being impossible to fix without breaking backward compatibility.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            remonvv Remon van Vliet
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: