Shard_merge, does it happen on the MongoS or the Primary Shard?

So while watching various lectures, I have noticed that the Shard_merge seems to be happen on the MongoS, however it has also been implied that it happens on the Primary Shard of that collection.

Or is the primary shard only ever used for Aggregation Commands merge operations?

Hi @NMullins,

Very interesting question. In aggregation pipeline, it depends on the load on the shards. If there is already overloading on Primary shard, it will route to a random shard to merge the results.

Here is the documentation link for more information: