Perils of removing a MongoDB shard key index

Posted on 01 Dec 2010 by Luke Ehresman

MongoDB 1.6 won’t let you shard a collection without an index on the shard key. I thought the requirement was only for sharding existing collections so after sharding a collection, I dropped the shard key index. MongoDB was perfectly happy letting me do this.

It wasn’t until a couple days later that I noticed my cluster was imbalanced. Investigating the logs, I noticed that all the chunk migrations were failing with the following message:

Turns out, shard keys must be indexed for chunk migration to happen. Without it, chunk migration will fail. Simply creating an index on the shard key fixed the problem and my cluster quickly started passing chunks around to rebalance itself.

Tebros Systems is a software incubator that creates
custom and hosted software solutions.

We are eager to solve difficult problems, create usable web apps, and make
your idea become reality. We have a wide range of experience from web
development to database optimization to usability analysis and more. Contact
us with your idea. We’ll walk you through a feasibility assessment and help
your project come to life.