If we want to sort our results, we have the following two options:
- If we are using the shard key in our sort criteria, then mongos can determine the order in which it has to query the shard or shards. This results in an efficient and, again, targeted operation.
- If we are not using the shard key in our sort criteria, then, as is the case with a query without any sort criteria, it's going to be a fan out query. To sort the results when we are not using the shard key, the primary shard executes a distributed merge sort locally before passing on the sorted result set to mongos.
A limit on the queries is enforced on each individual shard and then again at the mongos level, as there may be results from multiple shards. A skip ...