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

# Monitor and Improve Slow Queries with the Performance Advisor

*Only available on M10+ clusters*

The Performance Advisor monitors queries that MongoDB considers slow and suggests new indexes to improve query performance. The threshold for slow queries varies based on the average time of operations on your cluster to provide recommendations pertinent to your workload.

Recommended indexes are accompanied by sample queries, grouped by [query shape](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape), that were run against a collection that would benefit from the suggested index. The Performance Advisor considers workload activity across all nodes in the replica set, including secondaries, when generating index recommendations. The Performance Advisor doesn't negatively affect the performance of your Atlas clusters.

You can also monitor collection-level [query latency](https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document) with [Namespace Insights](https://www.mongodb.com/docs/atlas/namespace-insights.md#std-label-namespace-insights) and query performance with the [Query Profiler.](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler)

**Note:**

If the slow query log contains consecutive [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) stages in the aggregation pipeline, the two stages can [coalesce](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization/#-match----match-coalescence) into the first [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) stage and result in a single [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) stage. As a result, the query shape in the Performance Advisor might differ from the actual query you ran.

## Common Reasons for Slow Queries

If a query is slow, common reasons include:

- The query is unsupported by your current indexes.

- Some documents in your collection have large array fields that are costly to search and index.

- One query retrieves information from multiple collections with [$lookup.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/)

## Required Access

To view collections with slow queries and see suggested indexes, you must have [`Project Read Only`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Read-Only) access or higher to the project.

To view field values in a sample query in the Performance Advisor, you must have [`Project Observability Viewer`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Observability-Viewer), [`Project Data Access Read Only`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Data-Access-Read-Only), [`Project Data Access Read/Write`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Data-Access-Read-Write), or [`Project Data Access Admin`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Data-Access-Admin) access to the project.

To enable or disable the Atlas-managed slow operation threshold, you must have [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) access to the project. Users with [`Organization Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Organization-Owner) access must add themselves to the project as a `Project Owner`.

## Configure the Slow Query Threshold

By default, Atlas dynamically adjusts your slow query threshold based on the execution time of operations across your cluster. However, you can opt out of this feature and instead use a fixed slow query threshold of 100 milliseconds. We don't recommend that you set the fixed slow query threshold lower than 100 milliseconds.

**Note:**

Atlas clusters with MongoDB Search enabled don't support the Atlas-managed slow query operation threshold.

For Free clusters (formerly known as `M0`), Atlas disables the Atlas-managed slow query operation threshold by default and you can't enable it.

### Disable the Atlas-Managed Slow Operation Threshold

To disable the Atlas-managed slow operation threshold and use a fixed threshold of 100 milliseconds:

1. In Atlas, go to the Project Settings page.

   If it's not already displayed, select the organization that contains your desired project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

   In the sidebar, click the  icon next to Project Overview.

   The [Project Settings](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fsettings%2FgroupSettings) page

   displays.

2. In the [Project Settings](https://www.mongodb.com/docs/atlas/tutorial/manage-project-settings.md#std-label-project-settings) for the current project, toggle Managed Slow Operations to Off.

To disable the Atlas-managed slow operation threshold for your project using the Atlas CLI, run the following command:

```sh

atlas performanceAdvisor slowOperationThreshold disable [options]

```

To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas performanceAdvisor slowOperationThreshold disable.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-performanceAdvisor-slowOperationThreshold-disable/)

See [Disable Managed Slow Operation Threshold.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-disablemanagedslowoperationthreshold)

### Enable the Atlas-Managed Slow Operation Threshold

Atlas enables the Atlas-managed slow operation threshold by default. To re-enable the Atlas-managed slow operation threshold that you previously disabled:

In the [Project Settings](https://www.mongodb.com/docs/atlas/tutorial/manage-project-settings.md#std-label-project-settings) for the current project, toggle Managed Slow Operations to On.

To enable the Atlas-managed slow operation threshold for your project using the Atlas CLI, run the following command:

```sh

atlas performanceAdvisor slowOperationThreshold enable [options]

```

To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas performanceAdvisor slowOperationThreshold enable.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-performanceAdvisor-slowOperationThreshold-enable/)

See [Enable Managed Slow Operation Threshold.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-updategroupperformanceadvisormanagedslow)

## Index Considerations

Indexes improve read performance, but a large number of indexes can negatively impact write performance since indexes must be updated during writes. If your collection already has several indexes, consider this tradeoff of read and write performance when deciding whether to create new indexes. Examine whether a query for such a collection can be modified to take advantage of existing indexes, as well as whether a query occurs often enough to justify the cost of a new index.

## Access Performance Advisor

To access the Performance Advisor using the Atlas UI:

1. In Atlas, go to the Clusters page for your project.

   If it's not already displayed, select the organization that contains your desired project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

   In the sidebar, click Clusters under the Database heading.

   The [Clusters](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters) page displays.

2. Click the replica set where the collection resides.

   If the replica set is part of a sharded cluster, first click the sharded cluster containing the replica set.

3. Click Performance Advisor.

4. View recommendations.

   The Performance Advisor fetches index recommendations from the past 24 hours.

   - If the Performance Advisor has recommendations, click View Recommendations button in the Create Indexes section.

   - If the Performance Advisor has no recommendations, to look up index recommendations for up to the past 5 days, click Explore Recommendations in the Create Indexes section.

   The Performance Advisor ranks the indexes according to their Impact, which is based on the total wasted bytes read by the associated operations. To learn more about index ranking, see [Review Index Ranking.](https://www.mongodb.com/docs/atlas/performance-advisor/index-ranking.md#std-label-pa-index-ranking)

5. (Optional) Filter results.

   Filter the results by any of the following options:

   - Filter by shards and hosts

   - Filter by namespace

   - Filter by time range

   - Filter by date and time

### View Collections with Slow Queries

To return up to 20 namespaces in `<database>.<collection>` format for collections experiencing slow queries using the Atlas CLI, run the following command:

```sh

atlas performanceAdvisor namespaces list [options]

```

To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas performanceAdvisor namespaces list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-performanceAdvisor-namespaces-list/)

### View Slow Query Logs

To return query log line items for slow queries that the Performance Advisor and Query Profiler identify using the Atlas CLI, run the following command:

```sh

atlas performanceAdvisor slowQueryLogs list [options]

```

To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas performanceAdvisor slowQueryLogs list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-performanceAdvisor-slowQueryLogs-list/)

### View Suggested Indexes

To return suggested indexes for collections experiencing slow queries using the Atlas CLI, run the following command:

```sh

atlas performanceAdvisor suggestedIndexes list [options]

```

To learn more about the command syntax and parameters, see the Atlas CLI documentation for [atlas performanceAdvisor suggestedIndexes list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-performanceAdvisor-suggestedIndexes-list/)

### Access Performance Advisor with the MCP server

You can access the Performance Advisor with the [MongoDB MCP Server](https://www.mongodb.com/docs/mcp-server.md#std-label-what-is-mcp-server). This tool enables you to interact with your Atlas clusters in natural language from AI clients like Claude, Cursor, and Github Copilot.

To learn how to use the MongoDB MCP Server to get Performance Advisor recommendations, see [Access Performance Advisor with the MongoDB MCP Server.](https://www.mongodb.com/docs/atlas/performance-advisor/access-with-mcp.md#std-label-performance-advisor-mcp)

## Index Suggestions

The Performance Advisor ranks the indexes according to their Impact, which is based on the total wasted bytes read by the associated operations. To learn more about how the Performance Advisor ranks indexes, see [Review Index Ranking.](https://www.mongodb.com/docs/atlas/performance-advisor/index-ranking.md#std-label-pa-index-ranking)

To learn how to create indexes that the Performance Advisor suggests, see [Create Suggested Indexes.](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-pa-create-suggested-indexes)

### Index Metrics

Each index that the Performance Advisor suggests contains the following metrics. These metrics apply specifically to queries which would be improved by the index:

| Metric | Description |
| --- | --- |
| Execution Count | Number of queries executed per hour which would be improved. |
| Average Execution Time | Current average execution time in milliseconds for affected queries. |
| Average Query Targeting | Average number of documents read per document returned by affected queries. A higher query targeting score indicates a greater degree of inefficiency. For more information on query targeting, see [Query Targeting.](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-query-targeting) |
| In Memory Sort | Current number of affected queries per hour that needed to be sorted in memory. |
| Average Docs Scanned | Average number of documents scanned. |
| Average Docs Returned | Average number of documents returned. |
| Average Object Size | Average object size. |

### Sample Queries

For each suggested index, the Performance Advisor shows the most commonly executed query shapes that the index would improve. For each query shape, the Performance Advisor displays the following metrics:

| Metric | Description |
| --- | --- |
| Execution Count | Number of queries executed per hour which match the query shape. |
| Average Execution Time | Average execution time in milliseconds for queries which match the query shape. |
| Average Query Targeting | Average number of documents read for every document returned by matching queries. A higher query targeting score indicates a greater degree of inefficiency. For more information on query targeting, see [Query Targeting.](https://www.mongodb.com/docs/atlas/performance-advisor.md#std-label-query-targeting) |
| Average Docs Scanned | Average number of documents scanned. |
| Average Docs Returned | Average number of documents returned. |

The Performance Advisor also shows each executed sample query that matches the query shape, with specific metrics for that query.

### Query Targeting

Each index suggestion includes an Average Query Targeting score indicating how many documents were read for every document returned for the index's corresponding query shapes. A score of 1 represents very efficient query shapes because every document read matched the query and was returned with the query results. All suggested indexes represent an opportunity to improve query performance.

### Filter Index Suggestions

By default, the Performance Advisor suggests indexes for all clusters in the deployment. To only show suggested indexes from a specific collection, use the Collection dropdown at the top of the Performance Advisor.

You can also adjust the time range the Performance Advisor takes into account when suggesting indexes by using the Time Range dropdown at the top of the Performance Advisor.

### Limitations of Index Suggestions

#### Timestamp Format

The Performance Advisor can't suggest indexes for MongoDB databases configured to use the `ctime` timestamp format. As a workaround, set the timestamp format for such databases to either `iso8601-utc` or `iso8601-local`. To learn more about timestamp formats, see [mongod --timeStampFormat.](https://www.mongodb.com/docs/manual/reference/program/mongod/#std-option-mongod.--timeStampFormat)

#### Log Quantity

If a cluster experiences an activity spike and generates an extremely large quantity of log messages, Atlas may stop collecting and storing new logs for a period of time.

**Note:**

Log analysis rate limits apply only to the Performance Advisor UI, the Query Insights UI, and the Access Tracking UI. [Downloadable log files](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-downloadgroupclusterlog) are always complete.

#### Time Series Collections

The Performance Advisor doesn't provide performance suggestions for time series collections.

#### User Feedback

The Performance Advisor includes a user feedback button for Index Suggestions on dedicated clusters.

## Create Suggested Indexes

You can create [indexes](https://www.mongodb.com/docs/manual/core/indexes/) suggested by the Performance Advisor directly within the Performance Advisor itself. When you create indexes, keep the ratio of reads to writes on the target collection in mind. Indexes come with a performance cost, but are more than worth the cost for frequent queries on large data sets. To learn more about indexing strategies, see [Indexing Strategies.](https://www.mongodb.com/docs/manual/applications/indexes/)

### Behavior and Limitations

- You can't create indexes through the Performance Advisor if [Data Explorer](https://www.mongodb.com/docs/atlas/atlas-ui.md#std-label-atlas-ui) is disabled for your project. You can still view the Performance Advisor recommendations, but you must create those indexes from [`mongosh`.](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

- You can only create one index at a time through the Performance Advisor. If you want to create more simultaneously, you can do so using the [Atlas UI](https://www.mongodb.com/docs/atlas/atlas-ui/indexes.md#std-label-atlas-ui-indexes), a [driver](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver), or the [shell](https://www.mongodb.com/docs/atlas/mongo-shell-connection.md#std-label-connect-mongo-shell)

- Atlas always creates indexes for entire clusters. If you create an index while viewing the Performance Advisor for a single shard in a sharded cluster, Atlas creates that index for the entire sharded cluster.

### Procedure

To create a suggested index:

1. For the index you want to create, click Create Index.

   The Performance Advisor opens the Create Index dialog box and prepopulates the Fields based on the index you selected.

2. *(Optional)* Specify the [index options](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex.md#std-label-createIndex-options).

   ```javascript
   { <option1>: <value1>, ... }
   ```

   **Example:**

   The following options document specifies the `unique` option and the `name` for the index:

   ```javascript
   { unique: true, name: "myUniqueIndex" }
   ```

3. *(Optional)* Set the [Collation](https://www.mongodb.com/docs/manual/indexes/#indexes-and-collation) options.

   Use collation to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. The [collation document](https://www.mongodb.com/docs/manual/reference/collation/#collation-document) contains a `locale` field which indicates the [ICU Locale code](https://unicode-org.github.io/icu/userguide/locale/), and may contain other fields to define collation behavior.

   **Example:**

   The following collation option document specifies a locale value of `fr` for a French language collation:

   ```json
   { "locale": "fr" }
   ```

   To review the list of locales that MongoDB collation supports, see the [list of languages and locales](https://www.mongodb.com/docs/manual/reference/collation-locales-defaults.md#std-label-collation-languages-locales). To learn more about collation options, including which are enabled by default for each locale, see [Collation](https://www.mongodb.com/docs/manual/reference/collation.md#std-label-collation-document-fields) in the MongoDB manual.

4. *(Optional)* Enable building indexes in a rolling fashion.

   **Important:**

   Building an index in a rolling fashion reduces the resiliency of your cluster and increases index build times. We only recommend using rolling index builds when regular index builds do not meet your needs.

   If you decide to continue with a rolling index, consider that they must meet certain conditions to succeed. To ensure your index build succeeds, avoid the following design patterns that commonly trigger a restart loop:

   - Index key exceeds the [index key limit](https://www.mongodb.com/docs/manual/reference/limits/#mongodb-limit-Index-Key-Limit)

   - [Index name](https://www.mongodb.com/docs/manual/indexes/#index-names) already exists

   - Index on [more than one array field](https://www.mongodb.com/docs/manual/core/index-multikey/#compound-multikey-indexes)

   - Index on collection that has the [maximum number of text indexes](https://www.mongodb.com/docs/manual/reference/limits/#mongodb-limit-Number-of-Indexes-per-Collection)

   - Text index on collection that has the [maximum number of text indexes](https://www.mongodb.com/docs/manual/core/index-text/#one-text-index-per-collection)

   **Note:**

   The Atlas UI doesn't support building indexes with a rolling build for Free clusters and Flex clusters.

   For workloads which cannot tolerate performance decrease due to index builds, consider building indexes in a rolling fashion.

   To maintain cluster availability:

   - Atlas removes one node from the cluster at a time starting with a [secondary.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary)

   - More than one node can go down at a time, but Atlas always keeps a majority of the nodes online.

   Atlas automatically cancels rolling index builds that don't succeed on all nodes. When a rolling index build completes on some nodes, but fails on others, Atlas cancels the build and removes the index from any nodes that it was successfully built on.

   In the event of a rolling index build cancellation, Atlas generates an [activity feed event](https://www.mongodb.com/docs/atlas/tutorial/activity-feed.md#std-label-view-activity-feed) and sends a notification email to the project owner with the following information:

   - Name of the cluster on which the rolling index build failed

   - Namespace on which the rolling index build failed

   - Project that contains the cluster and namespace

   - Organization that contains the project

   - Link to the [activity feed event](https://www.mongodb.com/docs/atlas/tutorial/activity-feed.md#std-label-view-activity-feed)

   To learn more about rebuilding indexes, see [Build Indexes on Replica Sets.](https://www.mongodb.com/docs/manual/tutorial/build-indexes-on-replica-sets/)

   **Note:**

   [Unique](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex/#options-for-all-index-types) [index options](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex/#options) are incompatible with building indexes in a rolling fashion. If you specify `unique` in the Options pane, Atlas rejects your configuration with an error message.

5. Click Review.

6. In the Confirm Operation dialog box, confirm your index.

   **Important:**

   When an index build completes, Atlas generates an [activity feed event](https://www.mongodb.com/docs/atlas/tutorial/activity-feed.md#std-label-view-activity-feed) and sends a notification email to the project owner with the following information:

   - Completion date of the index build

   - Name of the cluster on which the index build completed

   - Namespace on which the index build completed

   - Project containing the cluster and namespace

   - Organization containing the project

   - Link to the [activity feed event](https://www.mongodb.com/docs/atlas/tutorial/activity-feed.md#std-label-view-activity-feed)
