Aggregation Pipeline and Sharded Collections¶
Changed in version 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.
Changed in version 3.6.
When aggregation operations run on multiple shards, the results are
routed to the
mongos to be merged, except in the
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.
Optimizations are subject to change between releases.