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

Move $match in front of $group if condition is on group key

    XMLWordPrintable

    Details

    • Backwards Compatibility:
      Fully Compatible
    • Sprint:
      Query 2019-06-03, Query 2019-06-17, Query 2019-07-01
    • Case:

      Description

      In case of views created on results of a $group, if the subsequent query is filtering on _id field then it should be possible to push that $match in front of $group transforming it into filter against whatever field is being grouped.

      Example:

      Vew definition:

      [ {$group:{_id:"$city", ...}} ] 
      

      Query on view:

      {$match: {_id:{$in:["NY", "SF"]}}}
      

      Pipeline transformation:

      // from
      [ {$group:{_id:"$city", ...}}, {$match: {_id:{$in:["NY", "SF"]}}} ] 
      // to
      [{$match: {city:{$in:["NY", "SF"]}}}, {$group:{_id:"$city", ...}} ] 
      

        Attachments

          Activity

            People

            Assignee:
            george.wangensteen George Wangensteen (Inactive)
            Reporter:
            asya Asya Kamsky
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: