> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# Analyze Query Performance

MongoDB provides several ways to examine the performance of your workload, allowing you to understand query performance and identify long-running queries. Understanding query performance helps you build effective indexes and ensure your application runs critical queries efficiently.

## Identify Slow Queries

Use the following methods to identify slow queries that occur on your deployment.

### Performance Overview

The following methods provide overviews of your deployment's performance. Use these methods to determine if there are performance issues that need to be addressed:

| Method | Availability | Description |
| --- | --- | --- |
| Use the Atlas Performance Advisor | M10+ Atlas clusters | The Atlas Performance Advisor monitors slow queries and suggests new indexes to improve performance. For more information, see [Monitor and Improve Slow Queries with the Performance Advisor.](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-performance-advisor) |
| Check ongoing operations in Atlas | M10+ Atlas clusters | You can use the [Atlas Real-Time Performance Panel](https://www.mongodb.com/docs/atlas/real-time-performance-panel.md#std-label-real-time-metrics-status-tab) (RTPP) to see current network traffic, database operations, and hardware statistics. |
| Check ongoing operations locally | Atlas clusters and self-hosted deployments | The [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) aggregation stage returns information on active operations and cursors. Use `$currentOp` to identify long-running or stuck operations that may be negatively impacting performance. You can also use the [`top`](https://www.mongodb.com/docs/manual/reference/command/top.md#mongodb-dbcommand-dbcmd.top) command to get additional operation count and latency statistics.. |
| Check server metrics | Atlas clusters and self-hosted deployments | For Atlas clusters, you can [view cluster metrics](https://www.mongodb.com/docs/atlas/monitor-cluster-metrics.md#std-label-monitor-cluster-metrics) to identify performance issues. For self-hosted deployments, the [`serverStatus`](https://www.mongodb.com/docs/manual/reference/command/serverstatus.md#mongodb-dbcommand-dbcmd.serverStatus) command provides metrics that can indicate poor performance and anomalies for query execution. |
| View common query shapes | Atlas clusters and self-hosted deployments | The [`$queryStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#mongodb-pipeline-pipe.-queryStats) aggregation stage returns information about common [query shapes](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes). `$queryStats` provides a holistic view of the kinds of queries being run on your deployment. |
| View index statistics | Atlas clusters and self-hosted deployments | The [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) aggregation stage returns information about your collection's indexes and how often individual indexes are used. Use `$indexStats` to identify unused indexes that can be removed to improve write performance. |
| View collection statistics | Atlas clusters and self-hosted deployments | The [`$collStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collstats.md#mongodb-pipeline-pipe.-collStats) aggregation stage returns statistical information on specific collections and their usage. `$collStats` provides information such as: Storage usage for the collection and its indexes; The average size of documents |

### Analyze a Slow Query

Use these methods to analyze a slow query and determine the cause of poor performance:

| Method | Availability | Description |
| --- | --- | --- |
| Use the Atlas Query Profiler | M10+ Atlas clusters | The Atlas Query Profiler shows long-running operations and performance statistics. For more information, see [Monitor Query Performance with the Query Profiler.](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-profile-database) |
| Enable the Database Profiler | Atlas clusters and self-hosted deployments | When enabled, the database profiler stores information about slow queries in the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection. For more information, see [Database Profiler.](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) |
| View slow queries in the diagnostic log | Atlas clusters and self-hosted deployments | MongoDB logs queries that exceed the slow operation threshold (default 100 milliseconds) in the [diagnostic logs.](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref) Check the diagnostic logs to identify problematic queries and see which queries would benefit from indexes. |
| View explain results | Atlas clusters and self-hosted deployments | Query explain results show information on the query plan and execution statistics. You can use explain results to determine the following information about a query: The amount of time a query took to execute; Whether the query used an index; The number of documents and index keys scanned to fulfill a query To view explain results, use the following methods: [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain); [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) cursor method To learn about explain results output, see [Explain Results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) and [Interpret Explain Plan Results.](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#std-label-interpret-explain-plan) |

## Perform Advanced Query Analysis

The following methods are suited for deeper investigation of problematic queries, and can provide fine-grained performance insights:

| Method | Availability | Description |
| --- | --- | --- |
| View plan cache statistics | Atlas clusters and self-hosted deployments | The [`$planCacheStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/plancachestats.md#mongodb-pipeline-pipe.-planCacheStats) aggregation stage returns information about a collection's [plan cache.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) The plan cache contains query plans that the query planner uses to efficiently complete queries. Generally, the plan cache should contain entries for your most commonly-run queries. |
