This page is about documents and replica sets. I show you where WiredTiger keeps every collection and index, and how two logs split the jobs: journal for crashes, oplog for the replica set. After it you will be able to find any collection's .wt file, read the oplog window, and check whether the cache is under pressure.
A document database. JSON-like documents in collections. Built to run as a replica set.
Good at: Records that genuinely differ per item. Catalogues and profiles. Spreading across machines with built-in sharding. Two logs: journal for crashes, oplog for the replica set.
Runs as: mongod processes in a replica set; mongos routers when shardedSame three layers as every engine: process, memory, disk. The layer rule is written once on the PostgreSQL page: name the layer first, then diagnose inside it.
Request path
Same idea as PostgreSQL: exact names, one job per log, one check per incident. The rule is written once on the PostgreSQL page. This table adds the operational logs a DBA reads first: server, error, slow.
| Log | Exact file name | Where it sits (on-prem) | What it does | What to check in it |
|---|---|---|---|---|
| MongoDB Journal | journal/WiredTigerLog.0000000123 | journal/ inside the dbPath | WiredTiger's write-ahead log. It covers the gap between checkpoints (about 60 s). j:true waits for this. | Check that the files exist and turn over. Check journal commit latency in db.serverStatus().wiredTiger.log. |
| MongoDB Oplog | local.oplog.rs | A capped collection in the local database. Not a file | Ordered record of every write on the primary. Secondaries tail it. Its size divided by write rate is the catch-up window. | rs.printReplicationInfo(). "log length start to end" is the window in hours. Compare it to your longest maintenance. |
| MongoDB mongod log | mongod.log | /var/log/mongodb/mongod.log | The server's diary. Elections. Slow operations (over the profiler threshold). Connection events. | Election events and slow-operation lines around the incident start. Stepdown and stepup pairs mark every failover. |
Same three outage rules as PostgreSQL: Safe live lever, Planned change, Do not touch. What each one means is written once on the PostgreSQL page.
| Parameter | What it does | During an outage |
|---|---|---|
| storage.wiredTiger.engineConfig.cacheSizeGB | Size of the WiredTiger cache. Default is about 50% of RAM minus 1 GB. | Planned change. It is set in the config file. Applying it means a rolling restart of the set. Mid-incident, the evidence comes first: serverStatus().wiredTiger.cache. The live fixes are killing the cache-churning operation or the pinned snapshot, not the cache size. |
| oplogSizeMB / replSetResizeOplog | Size of the capped oplog collection. Window equals size divided by write rate. | Safe live lever (dynamic in 4.4 and later). Enlarge the oplog before planned maintenance so the window exceeds the downtime. It cannot recover entries that already rolled off. |
| writeConcern / readConcern | Per-operation guarantees set by the application. How many members must acknowledge a write (w). Whether it must be journaled (j). Which writes a read may see. | Application change, not a server knob. Do not weaken w:'majority' mid-outage to make writes "fast again", unless rollback-on-election is explicitly acceptable. Shifting readPreference to secondaries sheds primary load but serves staler data. That is a routing decision, not a repair. |
Same rule as PostgreSQL: there is no hidden state. Every file here is inspectable with ls and du while the server runs. The full version is on the PostgreSQL page.
$ ls /var/lib/mongo WiredTiger # WiredTiger version marker WiredTiger.wt # WT's own metadata: where the # last checkpoint is WiredTiger.turtle # backup copy of that metadata _mdb_catalog.wt # THE MAP: "users" = which file? collection-2-4471….wt # ← collection "users" collection-5-9912….wt # ← collection "orders" index-3-4471….wt # ← the _id index of "users": # one file per index journal/ # THE JOURNAL (write-ahead log): WiredTigerLog.0000000123 mongod.lock # lock file; a stale one means the # last shutdown was not clean sizeStorer.wt storage.bson diagnostic.data/ # metrics mongod records on itself
Same pattern as PostgreSQL: five logs, one job each, and every operational budget is a time window. The full version is on the PostgreSQL page.
The other logs: PostgreSQL: WAL · MySQL · InnoDB: redo log and binary log · the pattern behind all five, and where they break
Same rule as PostgreSQL: every mechanism above is observable on a running server in under two minutes. The full version is on the PostgreSQL page.
Run it locally: docker-compose-mongo.yml starts MongoDB 8.0 on port 27017 with a shop database. docker compose -f docker-compose-mongo.yml up -d, then run the commands below against it.
// where is everything? db.adminCommand({getCmdLineOpts: 1}) // → parsed.storage.dbPath db.users.stats().wiredTiger.uri // → "table:collection-2-4471…" $ ls /var/lib/mongo/journal // → WiredTigerLog.0000000123 // the oplog: size, window, latest entry rs.printReplicationInfo() rs.status() // members + optime lag // cache pressure db.serverStatus().wiredTiger.cache
Problem. My query filters, sorts, and returns. It runs slow. I run explain. It shows a SORT stage. The index exists. The sort still happens.
Mechanism. A compound index stores keys in field order. Field 1 first. Field 2 inside field 1. Field 3 inside field 2. Put the equality field first. Put the sort field second. Put the range field last. That is ESR.
The equality match narrows the walk to one slice. Inside that slice, the sort field is already in order. The query reads rows in sorted order. The range field sits last. It trims the tail.
Put the fields in the wrong order and the sort breaks. A range field before the sort field breaks it. The index can no longer hand back rows in sort order. MongoDB adds a SORT stage. That stage sorts in memory. The limit is 100 MB. A sort past that limit fails unless the query allows disk use.
MongoDB caches the winning plan for a query shape. I add an index. I drop an index. The cached plan can go stale. I check the cached plans. Then I clear the cache for that collection. The next run picks a fresh plan.
Exact check. Build the index in ESR order. Then explain the query. Then check index use and plan cache.
Read explain for SORT stage. No SORT stage means the index order did the sorting. Read totalDocsExamined next to nReturned. A wide gap means the index is not narrowing the work.
One big customer's dashboard timed out. Everyone else was fast.
I checked distribution, not totals. One node was at 100 percent and the rest were idle. A monotonic shard key was sending every new write to the same shard.
The fix was the key, not more shards. Hash-prefix a monotonic shard key, or give the whale tenant its own shard. Choose the shard key from the query pattern before launch.
How to host MongoDB on-prem, on EC2, in Kubernetes, or on Atlas is on the Cloud page.
One command. It tells you how long a secondary can stay down and still catch up.
Read "log length start to end". That is the window in hours. Compare it to your longest maintenance.