From 4e648778590e50ceeb51c215c9ebdff80e9e7f53 Mon Sep 17 00:00:00 2001 From: Asya Kamsky Date: Thu, 11 Feb 2021 22:03:27 -0500 Subject: [PATCH] Correcting merging in sharded cluster statement Missing the merge on random shard when there's a blocking stage and allowDiskUse:true is specified. --- source/core/aggregation-pipeline-sharded-collections.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/core/aggregation-pipeline-sharded-collections.txt b/source/core/aggregation-pipeline-sharded-collections.txt index ce83212238d..db7bf9c7995 100644 --- a/source/core/aggregation-pipeline-sharded-collections.txt +++ b/source/core/aggregation-pipeline-sharded-collections.txt @@ -30,9 +30,11 @@ to be done on the primary shard. .. versionchanged:: 3.6 When aggregation operations run on multiple shards, the results are -routed to the :binary:`~bin.mongos` to be merged. However, :pipeline:`$out` -and :pipeline:`$lookup` must run on the :ref:`primary shard ` -and are aggregated there. +routed to the :binary:`~bin.mongos` to be merged except when :pipeline:`$out` +and :pipeline:`$lookup` are present, and must merge on the :ref:`primary +shard ` or when :ref:`allowDiskUse` is true and there is a +sorting or grouping stage present in which case one of the shards will be +randomly selected to perform the merge. Optimization ------------