content_image/668395.jpg content_image/668396.jpg
the chunks evenly across the shards. To divide the shard key values into chunks, MongoDB uses either range based partitioning or hash based partitioning . See the Shard Key (page 674) documentation for more information. 

## Range Based Sharding 

For range-based sharding , MongoDB divides the data set into ranges determined by the shard key values to provide range based partitioning . Consider a numeric shard key: If you visualize a number line that goes from negative infinity to positive infinity, each value of the shard key falls at some point on that line. MongoDB partitions this line into smaller, non-overlapping ranges called chunks where a chunk is range of values from some minimum value to some maximum value. 

Given a range based partitioning system, documents with “close” shard key values are likely to be in the same chunk, and therefore on the same shard. 

<img src='content_image/668395.jpg'>

## Hash Based Sharding 

For hash based partitioning , MongoDB computes a hash of a field’s value, and then uses these hashes to create chunks. 

With hash based partitioning, two documents with “close” shard key values are unlikely to be part of the same chunk. This ensures a more random distribution of a collection in the cluster. 

<img src='content_image/668396.jpg'>

