How do you monitor the performance of a MongoDB database?

Instruction: Explain the tools and practices you would use to monitor MongoDB's performance.

Context: This question assesses the candidate's knowledge of MongoDB monitoring tools and their ability to implement best practices in monitoring database performance.

Updated

Official answer

Monitor user-visible latency, errors and availability alongside database resource and workload metrics. Track latency distributions such as p95/p99, operation rates, examined-to-returned work, connection pressure, cache/disk behavior, replication lag and capacity trends. A low average can hide slow tail requests.

In mongosh, db.serverStatus() returns server metrics; opcounters is a field in that result, not a separate opcounters command. Its operation counters are cumulative since process start and include received operations, including failures. Compute rates from differences over elapsed time and account for restarts/resets. Operation counts are not necessarily counts of documents affected.

Use explain and appropriately scoped slow-query diagnostics to investigate expensive access paths. The database profiler and detailed logs can add overhead and expose query data, so configure sampling/thresholds, access and retention deliberately. Do not enable maximal profiling indefinitely without measuring its impact.

Correlate symptoms with deployments, traffic and resource changes. For example, rising tail latency plus high documents examined may suggest an access-path problem, whereas replication lag with saturated secondary I/O suggests a different bottleneck. Confirm the cause with evidence before changing indexes or capacity.

Set alerts from service objectives and sustained trends, include actionable context, and verify recovery after remediation. Keep version-specific metric definitions with the dashboard so renamed or changed counters do not silently mislead operators.

MongoDB serverStatus metrics, database profiler

Related Questions