Investigate completed slow MongoDB queries

A query that ended before you opened Active operations can still have a profiler record or a diagnostic log entry. Slow-query history groups those completed reads so you can see which patterns consumed the most recorded time.

Choose the source and verify coverage

  1. Open Server tools → Slow-query history. Choose Database profiler, select an interval and expand Profiler coverage. Check the listed databases and members. The app reads available records and leaves profiling settings unchanged.
  2. For saved diagnostic logs, choose Import log…. Identify the source member and select a structured MongoDB JSON log with one entry per line. Repeat for other files and compare their time spans.
  3. Select a pattern. Compare its command, application, members, count, cumulative recorded duration and individual completions. Find similar live queries looks for the same namespace, command and redacted shape running now.
Profiler history grouped by query shape with the reporting members and selected interval
The desktop sample makes the source and profiler coverage visible.

Tell a workload pattern from a single outlier

One 40-second read can share an interval with 120 reads lasting 800 ms each. The latter accumulate 96 seconds, even though no individual read takes a second. Overlapping operations contribute independently to that total.

Sampling, retention, access and source read limits affect the totals. Later cursor batches are excluded from imported find and aggregation command durations. A remembered profile can reopen imported redacted history while disconnected. A temporary profile keeps its imports for the session.

Compare a representative plan

  1. Open a recorded pattern and choose Compare plans. Select the database and collection for the experiment and enter a representative filter or aggregation. A redacted shape does not contain the original values.
  2. Choose Load indexes to pick an existing index by name. Run Explain, save a baseline, change the query or index and run Explain again. Compare returned rows, documents and keys examined, reported time and plan stages.
  3. Check equal results before comparing work. In a MongoDB rehearsal, the two selected indexes returned the same 50 records. One execution examined 4,901 documents and the other examined 50. A pipeline cursor’s count can differ from its final output.

Relate the interval to a server spike

Server overview samples every five seconds while its tab stays open, retaining up to 30 minutes per connection/window. Select the sample peak to open its ten-minute interval in history. Short-lived reads can fall between timeline samples.

In the sample, rs0-c:27017 first reaches five seconds of replication lag at 14:08 UTC. At 14:10 both secondaries are 38 seconds behind on apply. Under Recovery headroom, the source oplog overlaps one secondary by six hours and the other by four seconds. Check the actual sync source and treat unavailable measurements as unknown.