MK

martinkrizan.com / blog / a-mongodb-you-dont-have-to-babysit

A MongoDB you don't have to babysit

Most MongoDB pain I have seen was not MongoDB's fault. It was a missing index, a backup nobody had restored, and an alert that fired so often everyone muted it.

Indexes, before the traffic

The query planner will happily scan a collection until the day it cannot. Find those queries while the collection is small:

db.setProfilingLevel(1, { slowms: 50 });
db.system.profile.find({ planSummary: "COLLSCAN" }).sort({ ts: -1 }).limit(20);

Every COLLSCAN in that list is a decision you have not made yet. Either it is a small collection and you are fine forever, or it is not and you have a date with a production incident.

The backup is the restore

An untested dump is a file, not a backup. The job that matters is the one that restores last night's dump into a scratch database and counts documents:

mongorestore --drop --db restore_check /backup/latest
mongosh restore_check --quiet --eval 'db.orders.countDocuments()'

Run it weekly. The first time you do this, something will be wrong.

Alerts worth having

  • Replication lag above ten seconds
  • Disk above eighty percent
  • Any query over a second in the profiler
  • Connection count near the pool ceiling

That is the list. Everything else I have added over the years, I have later muted, which is the same as not having it — except that muting taught the team that alerts are noise.