Explain Sharding — Interview Answer — MongoDB Technical Interview Questions & Answers

Model answer covering shard keys and horizontal scaling.

Explain Sharding — Interview Answer

  • Model answer: Sharding splits a collection across shards using a shard key. mongos routes queries. For data too big for one machine.
  • Contrast replica set. Mention a bad shard key (low cardinality).

Technical Interview Tip: Split vs copy. Name mongos.

Code Examples for Explain Sharding — Interview Answer

Explain Sharding — Interview Answer — working example

// Replica set: primary takes writes; secondaries replicate.
rs.status()

// Sharding: data partitioned by shard key across shards
sh.status()
sh.shardCollection("prep_pilot.orders", { customerId: "hashed" })
db.orders.find({ customerId: 42 })

Explain Sharding — Interview Answer — replica sets give HA; sharding scales writes/data horizontally via a shard key.

How to Explain Explain Sharding — Interview Answer to an Interviewer

What is sharding?

Partition data across servers Shard key + mongos