MongoDB Documentation, Release 3.0.4 Pipeline Expressions Aggregation Pipeline Behavior Pipeline Operators and Indexes Early Filtering Additional Features 441 7.2. Aggregation Concepts The aggregation pipeline has an internal optimization phase that provides improved performance for certain sequences of operators. For details, see Aggregation Pipeline Optimization (page 447). The aggregation pipeline supports operations on sharded collections. See Aggregation Pipeline and Sharded Collec- tions (page 450). Placing a $match pipeline stage followed by a $sort stage at the start of the pipeline is logically equivalent to a single query with a sort and can use an index. When possible, place $match operators at the beginning of the pipeline. If your aggregation operation requires only a subset of the data in a collection, use the $match , $limit , and $skip stages to restrict the documents that enter at the beginning of the pipeline. When placed at the beginning of a pipeline, $match operations use suitable indexes to scan only the matching documents in a collection. Changed in version 2.6: In previous versions, for very select use cases, an index could cover a pipeline. Even when the pipeline uses an index, aggregation still requires access to the actual documents; i.e. indexes cannot fully cover an aggregation 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. The $match and $sort pipeline operators can take advantage of an index when they occur at the beginning of the pipeline. 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. For more information on expressions, see Expressions (page 470). Some pipeline stages takes a pipeline expression as its operand. Pipeline expressions specify the transformation to apply to the input documents. Expressions have a document (page 168) structure and can contain other expression (page 470). Pipeline expressions can only operate on the current document in the pipeline and cannot refer to data from other documents: expression operations provide in-memory transformation of documents. Generally, expressions are stateless and are only evaluated when seen by the aggregation process with one exception: accumulator expressions. The accumulators, used with the $group pipeline operator, maintain their state (e.g. totals, maximums, minimums, and related data) as documents progress through the pipeline.