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

Use a covered and streaming plan for $group, $sum:1 queries

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Query Optimization
    • Query 2019-07-29

      A very common use of an aggregation is to count elements by group:

      db.items.aggregate([ {$group: {_id: "$category", count: {$sum: 1}}}])
      

      If there is an index over category, this pipeline could be covered and no document retrieval is necessary.

      Since this is a quite common pattern, you may take it into account and make use of indexes.

            Assignee:
            backlog-query-optimization Backlog - Query Optimization
            Reporter:
            stoma Nicolas Dascanio
            Votes:
            11 Vote for this issue
            Watchers:
            21 Start watching this issue

              Created:
              Updated: