Skip to main content

What is a "chunk" in MongoDB?

A chunk in MongoDB is a logical portion of data inside a sharded collection, representing a range of shard key values. MongoDB splits a collection into such chunks and then distributes them across shards.

How this works

  • Data isn't stored one document per shard, it's grouped into chunks
  • Each chunk describes a range of the shard key, for example:
javascript
{ shardKey: 1 } from 100 to 199 → shard A { shardKey: 1 } from 200 to 299 → shard B
  • If a chunk gets too large, MongoDB automatically splits it (chunk split)
  • To balance load, chunks can move between shards (chunk migration)

Why chunks are needed

  1. Flexible data distribution MongoDB moves chunks, not individual records. That's simpler and faster.
  2. Load balancing If one shard is overloaded, some of its chunks can be moved to others.
  3. Automatic scaling management The cluster keeps track of chunk size and how evenly they're distributed on its own.

The key idea

  • shard key → defines the ranges
  • chunk → holds a specific range
  • shard → holds a set of chunks

Summary

A chunk is a range of data by shard key, the smallest unit of distribution in MongoDB sharding. Chunks are exactly what provides balance and flexibility in horizontal scaling.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.