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

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

    • 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:
            christopher.harris@mongodb.com Chris Harris
            Reporter:
            stoma Nicolas Dascanio
            Votes:
            13 Vote for this issue
            Watchers:
            28 Start watching this issue

              Created:
              Updated: