翻译或纠错本页面

聚合管道和分片集合

On this page

聚合管道支持在 分片 集合执行,这一章节讲述了 聚合管道 在分片集合上运行的特点。

特点

在 3.2 版更改.

If the pipeline starts with an exact $match on a shard key, the entire pipeline runs on the matching shard only. Previously, the pipeline would have been split, and the work of merging it would have to be done on the primary shard.

For aggregation operations that must run on multiple shards, if the operations do not require running on the database’s primary shard, these operations will route the results to a random shard to merge the results to avoid overloading the primary shard for that database. The $out stage and the $lookup stage require running on the database’s primary shard.

优化

将聚合管道分为两个步骤,极大的方便了对集群的性能做多个方面的优化。

使用 db.collection.aggregate()explain 选项可以获得管道分裂的详细信息。

Optimizations are subject to change between releases.