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

New projection operator $elemMatch

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.1.2
    • Component/s: Querying
    • Labels:
      None

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                19 Vote for this issue
                Watchers:
                18 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: