Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-9547

Docs for SERVER-19153: Conditionally push $match before $project

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Last comment by Customer:
      true
    • Sprint:
      KANBAN BUCKET

      Description

      Engineering Ticket Description:

      I was looking at the optimizing aggregation pipelines docs page and didn't see this one listed.

      This is only possible if the subsequent $match doesn't use any computed fields, but there could be a large win with regards to index usage if you could move the $match prior to a $project.

      For example:

      { $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } },
      { $match: { a : { $gt: 10 } }
      

      is the same as

      { $match: { a : { $gt: 10 } },
      { $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } }
      

      because the $match is only using fields that exist in the original document.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nick.larew Nicholas Larew
              Reporter:
              emily.hall Emily Hall
              Participants:
              Last commenter:
              Jonathan Dahl Jonathan Dahl
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                4 years, 13 weeks, 2 days ago
                Date of 1st Reply: