Explain Replica Sets — Interview Answer — MongoDB Technical Interview Questions & Answers

Model answer covering primary/secondary failover.

Explain Replica Sets — Interview Answer

  • Model answer: A replica set is copies of the data. Primary takes writes. Secondaries replicate. On failure, election of a new primary.
  • Atlas clusters are replica sets. Not the same as sharding.

Technical Interview Tip: Replica = HA copies.

Code Examples for Explain Replica Sets — Interview Answer

Explain Replica Sets — 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 Replica Sets — Interview Answer — replica sets give HA; sharding scales writes/data horizontally via a shard key.

How to Explain Explain Replica Sets — Interview Answer to an Interviewer

Replica set?

Primary + secondaries Automatic failover