Confusion regarding where the final Merging / Sorting of data happens (Mongos or Primary Shard?)
Lecture: Sharding Architecture, which is a part of Chapter 3 of course M103, at 3:18 states “Each individual shard is going to send the results back to Mongos. Mongos will gather the results and, may be, sort the results if the query mandated it. This stage is called SHARD_MERGE and it takes place on the Mongos. Once the Shard merging is complete, Mongos will return the results back to the client.
Lecture: Queries in a Sharded Cluster, which is also a part of Chapter 3 of course M103, at 1:20 states “Mongos opens a cursor against each of the targeted shards. Each cursor executes the query predicate and returns any data returned by the query for that shard. The mongos now has results from each targeted shard. The mongos merges all the results together to form the total set of documents that fulfils this query and then returns that set of documents to the client application.”
Thus, the above 2 lectures in course M103, give an impression that Merging / Sorting of data received from individual Shards, happens on Mongos. However course M201, states it otherwise
Lecture: Performance Consideration in Distributed Systems Part 2 , which is a part of Chapter 5 of course M201, at 4:15 states “Once the local sort is performed, then a final Sort Merge needs to occur at the Primary Shard of our database. Once that sort merge is performed, we return back the information to our client.”
Thus, as per course M201, Merging / Sorting of data happens on the Primary Shard.
Request you to please clarify where does Merging / Sorting happen in a Sharded Cluster??