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

New projection operator $elemMatch

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.1.2
    • Affects Version/s: None
    • Component/s: Querying
    • None

      Instead of a $ positional operator in projections ( as proposed here: http://jira.mongodb.org/browse/SERVER-828 ), I think that we could use a $elemMatch operator in projections, which will be used similiar to $slice.
      An example in pseudo-js:
      doc = {'a' : [

      {'b':1}

      ,

      {'b':2}

      ,

      {'b':3}

      ],'c' :4}

      project( {'a' : [

      {'b':1}

      ,

      {'b':2}

      ,

      {'b':3}

      ] }, {'a':{$elemMatch:

      {'b':2}

      }} )
      will be evaluated to:
      {'a' : [

      {'b':2}

      ],'c' :4}

      project( {'a' : [

      {'b':1}

      ,

      {'b':2}

      ,

      {'b':3}

      ] }, {'a':{$elemMatch:{'b':{'$gte':2}}}} )
      will be evaluated to:
      {'a' : [

      {'b':2}

      ,

      {'b':3}

      ],'c' :4}

      The advantage over the $-operator is that, the projection is completly independent from the matching. So you could match on something completly different and return only the entries you want. Furthermore this should be easier to implement.

      The only problem I see is that, you will in many cases repeat yourself, because you want to extract the fields you are querying for.

            Assignee:
            benjamin.becker Ben Becker
            Reporter:
            baju Hannes
            Votes:
            19 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved: