Aggregation Pipeline and Sharded Collections聚合管道和分片集合

On this page本页内容

The aggregation pipeline supports operations on sharded collections.聚合管道支持对分片集合的操作。This section describes behaviors specific to the aggregation pipeline and sharded collections.本节描述特定于聚合管道和分片集合的行为。

Behavior行为

Changed in version 3.2.在版本3.2中更改。

If the pipeline starts with an exact $match on a shard key, the entire pipeline runs on the matching shard only.如果管道在分片键上以精确的$match开始,则整个管道仅在匹配的分片上运行。Previously, the pipeline would have been split, and the work of merging it would have to be done on the primary shard.以前,管道会被拆分,合并管道的工作必须在主碎片上完成。

Changed in version 3.6.在版本3.6中更改。

When aggregation operations run on multiple shards, the results are routed to the mongos to be merged.当聚合操作在多个碎片上运行时,结果将路由到要合并的mongosHowever, $out and $lookup must run on the primary shard and are aggregated there.但是,$out$lookup必须在主分片上运行并在那里聚合。

Optimization优化

When splitting the aggregation pipeline into two parts, the pipeline is split to ensure that the shards perform as many stages as possible with consideration for optimization.当将聚合管道拆分为两部分时,管道将被拆分,以确保碎片执行尽可能多的阶段,同时考虑优化。

To see how the pipeline was split, include the explain option in the db.collection.aggregate() method.要查看管道是如何分割的,请在db.collection.aggregate()方法中包含explain选项。

Optimizations are subject to change between releases.优化可能会在不同版本之间发生变化。