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

Allow covered queries for first stage of Pipeline Aggregation

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Labels:
      None
    • Fully Compatible

      In select cases, it would be beneficial to users if they could make use of covered queries as the first stage of a pipeline aggregation. One use case would be for aggregating the metadata on a collection with a very large blob on each document, where the blob is not part of the query.

      My suggestion would be that if an aggregations starts off with a combination of $match, $sort, and $project, with the $project required, then it be considered for a covered query by the planner. Any of these combinations should be directly translatable to a .find() which does have the potential to be covered.

      Example:

      db.coll.insert({
        created: ISODate('2014-07-04'),
        type: 'Blog',
        size: 1234567,
        title: 'My Title',
        body: '<2MB text string>',
      })
      
      db.coll.ensureIndex({created:1, type: 1, size:1})
      
      db.coll.aggregate([
        {$match: {created: {$gte: ISODate('2014-01-01')}}},
        {$project: {size: 1, type:1, _id :0}},
        // Up to here is a covered query.
        {$group: {_id: '$type',
                  total_size: {$sum: '$size'},
                  count: {$sum: 1}}}
        ])
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            rod.adams@mongodb.com Rod Adams
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: