Aggregation Pipeline Behavior
In MongoDB, the aggregate command operates on a single collection, logically passing the entire collection into
The aggregation pipeline. To optimize the operation, wherever possible, use the following strategies to avoid scanning
The entire collection.
Aggregation Pipeline Performance
In MongoDB, the aggregation command operates on a single collection, logically, the entire collection is passed into the aggregation pipeline. To optimize the operation, use the following strategies wherever possible to avoid scanning the entire collection.
Pipeline Operators and Indexes
The $match and $sort pipeline operators can take advantage of a index when they occur at the beginning of the
Pipeline.
New in version 2.4:the $geoNear pipeline operator takes advantage of a geospatial index. When using $geoNear,
The $geoNear pipeline operation must appear as the first stage in an aggregation pipeline.
Even when the pipeline uses a index, aggregation still requires access to the actual documents; i.e. indexes cannot
Fully cover an aggregation pipeline.
Changed in version 2.6:in previous versions, for very select Use cases, an index could cover a pipeline.
Pipeline Operations and indexing
For $match and $SORTD pipeline operations, the benefits of indexing can be fully leveraged when they occur at the beginning of the pipeline.
In the new version 2.4: $geoNear pipeline Operation leverages the geospatial index geospatial, when using geospatial,