What is a chunk in sharding?
A chunk consists of a subset of sharded data. Each chunk has a inclusive lower and exclusive upper range based on the shard key. MongoDB splits chunks when they grow beyond the configured chunk size. A chunk that only contains documents with a single shard key value cannot be split.
How do I split a collection in MongoDB?
When you shard a collection that has existing data, MongoDB automatically creates chunks to evenly distribute the collection. To split data effectively in a sharded cluster you must consider the number of documents in a chunk and the average document size to create a uniform chunk size.
Can a chunk grow beyond the size of the shard?
In some cases, chunks can grow beyond the specified chunk size but cannot undergo a split . The most common scenario is when a chunk represents a single shard key value. Since the chunk cannot split, it continues to grow beyond the chunk size, becoming a jumbo chunk.
What happens when I change the size of a chunk?
Changing the chunk size affects when chunks split but there are some limitations to its effects. Automatic splitting only occurs during inserts or updates. If you lower the chunk size, it may take time for all chunks to split to the new size. Splits cannot be “undone”.
What happens when a chunk is split in MongoDB?
A chunk may be split into multiple chunks where necessary. Inserts and updates may trigger splits. Splits are an efficient meta-data change. To create splits, MongoDB does not migrate any data or affect the shards. Splits may lead to an uneven distribution of the chunks for a collection across the shards.
How does The sharding operation work in MongoDB?
The sharding operation creates empty chunks to cover the entire range of the shard key values and performs an initial chunk distribution. By default, the operation creates 2 chunks per shard and migrates across the cluster. You can use numInitialChunks option to specify a different number of initial chunks.