MongoDB Common Problems
The recurring MongoDB failure modes and what actually resolves each of them.
No primary available
Writes fail with "not master" or a server selection timeout. The replica set cannot form a majority.
Check rs.status() from any reachable member: how many are visible, and in what state. The cause is
usually a network partition, a failure domain hosting the majority, or an even-member configuration
with an arbiter. See the lost primary playbook.
A secondary needs a full resync
A member that was down longer than the oplog window can no longer catch up. It reports RECOVERING
and stays there.
Either resync it (initial sync copies the whole dataset, loading the source), or restore it from a recent backup and let it catch up from there. Prevent recurrence by increasing the oplog size — see Replica Sets.
Queries suddenly slow after growth
Almost always the working set no longer fits in the WiredTiger cache, or a query that was fast on a small collection is a collection scan on a large one.
db.setProfilingLevel(1, { slowms: 100 });
db.system.profile.find({ planSummary: "COLLSCAN" }).sort({ ts: -1 }).limit(10);Add the index, or add memory. Both are legitimate; the profiler tells you which.
In-memory sort exceeded the limit
Sort exceeded memory limit of 104857600 bytes. The query sorts more documents than the limit
allows and no index provides the order.
The correct fix is an index that supports the sort — see the ESR rule in
Index Design. allowDiskUse makes it complete, slowly, and does not
address the cause.
Write conflicts under load
WriteConflict errors from transactions or from concurrent updates to the same document. WiredTiger
uses optimistic concurrency, so conflicting writers abort and must retry.
Reduce contention by spreading writes across documents — a shared counter document is the classic hotspot — and make sure the driver's retry logic is enabled.
Connection storms after a failover
When a primary steps down, every client reconnects at once. Without bounded pools and jittered retries, the new primary is overwhelmed the moment it becomes available.
Configure pool sizes, serverSelectionTimeoutMS and retry backoff in the driver, and verify the
behaviour by performing a deliberate rs.stepDown() in a test environment.
Jumbo chunks in a sharded cluster
A chunk that cannot be split because every document in it shares one shard key value. It cannot migrate, so the cluster stays unbalanced.
This is a shard key problem. Changing the key means resharding the collection — see Sharding.
Disk usage does not fall after deleting documents
WiredTiger does not return free space to the filesystem automatically; deleted space is reused by the same collection.
db.runCommand({ compact: "orders" });Index build affects production
Index builds consume I/O, memory and CPU, and replicate to secondaries. Start them during low traffic, watch replication lag while they run, and know how to abort:
db.currentOp({ "command.createIndexes": { $exists: true } });
db.killOp(opid);