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

Unexpected matching behaviour for current $pull with $elemMatch syntax

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.6.3
    • Component/s: Querying
    • None
    • Environment:
      All
    • Major Change

      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.

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

              Created:
              Updated:
              Resolved: