<!-- llms-explorer concept facts · https://llms-explorer.com/tree/querystats-and-currentop-as-alternatives-to-the-profiler/ · pack 2026-10-31 · ~2149 tokens -->

# $queryStats and $currentOp as alternatives to the profiler

> Source-anchored research for $queryStats and $currentOp as alternatives to the profiler. Run status: COMPLETED.

Parent: [Database Profiler vs Query Profiler](https://llms-explorer.com/tree/database-profiler-vs-query-profiler/) · 5 facets · 22 facts · page: https://llms-explorer.com/tree/querystats-and-currentop-as-alternatives-to-the-profiler/

## How it works

- MongoDB 9.0 expands $queryStats to writes and changes its output organization. Consumers should validate their parsing when upgrading. (high confidence) (verified as of 2026-10-09) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- MongoDB issue SERVER-125570 reports costly full-store scanning when filtering $queryStats by keyHash, including a production observation near 30 seconds. This scopes collection overhead; it is not a benchmark for all deployments or a guarantee about a released version. (low confidence) (verified as of 2026-10-22) — [source](https://jira.mongodb.org/browse/SERVER-125570)
- MongoDB explicitly recommends considering $queryStats before enabling the database profiler because profiling can degrade performance. This recommendation does not make $queryStats a complete replacement for detailed per-operation evidence. (medium confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md)
- $queryStats is not a durable audit trail: the server implementation documents metric resets on restart or LRU eviction and skew from rate limiting, while the manual describes an in-memory virtual collection. Export observations externally when retained comparisons are needed. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)

## How-to and procedures

- Run db.getSiblingDB("admin").aggregate([{ $currentOp: { allUsers: true } }, { $match: { secs_running: { $gt: 2 } } }]) to find operations still running beyond two seconds. Inspect active, waitingForLock, planSummary, client information and the command to investigate the cause. (medium confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/monitor-slow-queries.md)

## Problems, failure modes and limitations

- Periodic $currentOp collection can miss operations that start and finish between polls. Percona documents this limitation in its real-time analytics; preserving snapshots or exports is necessary if those live observations must remain available later. (high confidence) — [source](https://www.percona.com/blog/what-is-running-on-my-mongodb-right-now-real-time-analytics-in-pmm/)
- SERVER-132513 documents a failure where nesting a queryStats key in the cursor response could exceed the 200-level depth limit and fail the aggregation. The issue lists fixes in 9.0.0-rc2 and 9.1.0-rc0; it does not establish that all releases are affected. (low confidence) (verified as of 2026-10-23) — [source](https://jira.mongodb.org/browse/SERVER-132513)

## Comparisons and alternatives

- The MongoDB 9.0 manual describes default sampling of 1% of read and write operations, so returned counts and execution times cover sampled operations rather than the whole workload. NoSQLBooster independently documents adapting its 11.2 support to this sampling and the reorganized output layout. (medium confidence) (verified as of 2026-10-26) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- $currentOp must start an admin-database pipeline. On authenticated standalone servers and replica sets, viewing all users requires inprog; authenticated sharded clusters require inprog to run the stage. localOps selects router-local versus shard operations on mongos. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/)
- $queryStats provides aggregated runtime statistics for recorded operations in an in-memory store. $currentOp provides one document per current operation or session, so it serves live investigation rather than a retained history of completed operations. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- $queryStats must run as the first stage against admin, rather than a specific collection. The manual requires queryStatsRead, plus queryStatsReadTransformed when transformIdentifiers is requested; clusterMonitor includes both privileges. The manual documents enablement on Atlas tiers M10 and above. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- MongoDB warns that $queryStats is unsupported and its output format may change. Its manual and NoSQLBooster release notes describe a MongoDB 9.0 metrics-layout change, illustrating why consumers must check server-version compatibility rather than hard-code an assumed schema. (medium confidence) (verified as of 2026-10-26) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- Percona implements a practical $currentOp consumer in PMM Real-time Query Analytics: it shows running operations, keeps live data in memory, and allows pausing and exporting a snapshot. This complements analysis of completed operations rather than replacing that history. (medium confidence) (verified as of 2026-10-06) — [source](https://www.percona.com/blog/what-is-running-on-my-mongodb-right-now-real-time-analytics-in-pmm/)

## Facts and statements

- MongoDB warns that database profiling can degrade performance and explicitly lists $queryStats as an alternative to consider. The profiler writes operation records to each profiled database's capped system.profile collection. (low confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md)
- $queryStats returns aggregated runtime metrics for recorded query executions from an in-memory store; it does not return a profiler-style document for each individual execution. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- $currentOp exposes active operations and optionally idle cursors, connections and transaction sessions. It can reveal a long-running operation before the completion record used by profiler-based analysis exists. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/)
- The query-stats store is bounded and uses LRU eviction. The implementation documentation warns that eviction and server restarts reset metrics, so consumers must not treat the counters as permanent history. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- MongoDB labels $queryStats unsupported and warns that its output format may change; it requires the admin database and first pipeline position. (low confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md)
- Datadog's MongoDB integration 10.11.0 changelog records removing a server-side sort from query-metrics collection to avoid queryStats sort memory failures. This is concrete evidence that the collection pipeline itself needs resource testing. (low confidence) (verified as of 2026-07-08) — [source](https://github.com/DataDog/integrations-core/blob/master/mongo/CHANGELOG.md)
- Datadog's MongoDB integration 8.5.0 added lsid and transaction details from $currentOp for activity sampling, providing an independent implementation example of using live operation data. (low confidence) (verified as of 2025-02-20) — [source](https://github.com/DataDog/integrations-core/blob/master/mongo/CHANGELOG.md)
- $currentOp must be the first pipeline stage and run on admin. On authorization-enabled standalone servers and replica sets, allUsers:true requires inprog; on authorization-enabled sharded clusters, running $currentOp requires inprog. Missing privileges can therefore hide cross-user activity or prevent collection. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/)
- On mongos, $currentOp with localOps:true reports operations local to that router; localOps:false reports operations on shards. localOps has no effect on mongod. Choose the scope explicitly before interpreting an empty live view. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/)
