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

XMLWordPrintableJSON

    • Query Optimization
    • Query 2019-07-29
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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:
            Unassigned
            Reporter:
            Nicolas Dascanio
            Votes:
            13 Vote for this issue
            Watchers:
            29 Start watching this issue

              Created:
              Updated: