MongoDB Sharding – Using Zone Tag with Single Key Value

mongodbsharding

Suppose I have a zone tag that has a range of exactly 1 key value, such as the letter A. Further, suppose I assign this zone to two shards. Will the data with a shard key of A be put on both shards?

My understanding leads me to say no because it will put the initial chunk on one of the two shards and since that chunk cannot be split because it encompasses only a single shard value, this means that a migration will never happen, so the other shard will sit empty.

Best Answer

Your understanding is correct: a chunk can only be associated with a single shard. A chunk range representing a single shard key value will be an indivisible chunk, so assigning this range to multiple shards will not result in data distribution across multiple shards.

If the data in this chunk eventually exceeds the chunk size limit (64 megabytes by default), the chunk will be flagged as a jumbo chunk and will be ignored for future migration activity.

Shard keys with limited cardinality (or outliers with high frequency) should generally be avoided as they will lead to data imbalance and performance challenges.