OK, let’s break this down:

  1. I have a sharded MongoDB cluster on my local system
  2. Up and running inside Docker.
  3. Then I tried to see how it distributes documents across shards.
  4. So first I created like 1000 document, but they all ended up in one shard replica set.
  5. So I got confused since I though a range sharding would just split data based on alphabets (remember that my shard key is handle), something like a to n and n to z.
  6. I read in the doc
    • The sharding operation creates a single empty chunk to cover the entire range of the shard key values.
    • After the initial chunk creation, the balancer migrates the initial chunk across the shards as appropriate as well as manages the chunk distribution going forward.
  7. But to my surprise when I decided to go all out after and create like 40000 documents it started to split them.

Now the weird thing is that it failed to distribute it evenly. I have like 11000 document in shard replica set number 1 and the rest are on the shard replica set number 2.

Any similar exp? Am I missing something?

NOTE: I did not change anything, except that I increase how much data I was saving in my NestJS code.