intermediateMongoDB — Indexing, Replica Sets & Sharding
What makes a good MongoDB shard key?
A good shard key has: 1) High cardinality: many distinct values (userId is good; status with 3 values is bad). 2) Even distribution: documents spread evenly (random or hashed UUIDs are good; sequential IDs create hotspots). 3) Query isolation: present in most query filters (avoids scatter-gather). 4) Low frequency: no single value accounts for a large chunk of data (hotspot). Common shard key choi
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response