Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting in case of Sharding in mongodb

I have Implemented sharding in mongodb when we shard a collection to two mongod shards on the basis of hashed shard key, so It does a parallel sort inside shards. After that, how it sorts the collection on the basis of _id? and what may be the other points of consideration? what are:

  1. Limitation of hashed shard key?
  2. what sort procedure mongo query router use to sort the records fetched from the shards?
  3. Whether the query will be affected due to network latency?
like image 549
niteshbisht Avatar asked Oct 21 '22 08:10

niteshbisht


1 Answers

  1. Not sure.

  2. If you don't specify a sort, mongo will return records round-robin from the shards, which I assume means there is no guarantee of any specific ordering, or even reproducible order from query to query. If you have an explicit sort, the primary shard will perform a merge sort. See the mongos docs

  3. Of course.

(This is an old question but it comes up pretty high in Google results.)

like image 77
Aidan Ryan Avatar answered Oct 28 '22 00:10

Aidan Ryan