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.
彙總管道表現
在Mongodb,彙總命令在單個collection上進行操作,邏輯上是吧整個collection傳進彙總管道。為了最佳化操作,儘可能的在能用到的地方使用以下的策略去避免掃描整個collection。
Pipeline Operators and Indexes
The $match and $sort pipeline operators can take advantage of an 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 an 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.
管道操作以及索引
對於 $match and $sortd管道操作,當他們發生在管道的開始可以充分利用索引的優勢。
在新的版本2.4中: $geoNear管道操作利用了地理空間索引geospatial,當使用geospatial,