Docs Menu
Docs Home
/
Atlas
/ /

Monitor Query Performance with Query Profiler

Only available on M10+ clusters

The Query Profiler diagnoses and monitors performance issues. This monitoring can expose slow-running queries and their key performance statistics in the Atlas UI.

Atlas collects and displays statistics from any of your mongod instances. The Query Profiler identifies slow queries based on log data from your mongod instances. Atlas displays this data on the Query Insights tab in the Query Profiler section of an instance.

Note

The Query Profiler differs from the Database Profiler. The Query Profiler identifies specific inefficient queries based on entries from your mongod logs. The Database Profiler returns detailed information about commands executed on the mongod based on the specified profiling level. Changing the profiling level doesn't impact the slow queries displayed in the Query Profiler.

The Atlas Query Profiler shows operations across your entire cluster by default. You can filter the hosts for which operations the Query Profiler displays data with the Filter by Hosts dropdown, which allows you to view data related to one or more specific hosts or to view primary or secondary host groups. The Query Insights tab displays information to reveal slow database operations over a set time frame, such as the following:

  • Operation Execution Time

  • Docs Examined : Returned Ratio

The Atlas Query Profiler supports binning operations of the same type running on the same collection around the same timestamp in order to support additional datapoints.

In order to support additional datapoints, the Atlas Query Profiler supports binning operations that meet the following critera:

  • The operations are of the same operation type.

  • The operations are running on the same namespace.

  • The operations have matching hasSort and usedIndex boolean values.

  • The operations are executed around the same timestamp.

Atlas manages the threshold for slow operations for each mongod host based on average operation execution time on that host. This threshold can be changed using the db.setProfilingLevel mongosh command.

Note

Changing the threshold for slow operations using db.setProfilingLevel can impact performance and system log settings. Carefully consider any performance and security implications before you use db.setProfilingLevel to adjust the Query Profiler settings on a production deployment. Query Profiler settings reset to default values following a node restart.

Additionally, zooming in on the x axis of the scatterplot will refetch slow operations and may provide more detailed fidelity of slow operations during the selected timeframe.

Note

To opt out of the Atlas-managed slow operation threshold and use a fixed slow query threshold of 100 milliseconds instead, use the Atlas Administration API. See Disable Managed Slow Operation Threshold. For M0 clusters, Flex clusters and Serverless instances, Atlas disables the Atlas-managed slow query operation threshold by default and you can't enable it.

Important

Please read the following considerations before you enable the Query Profiler.

Profile data may include sensitive information including the content of database queries. Ensure that exposing this data to Atlas is consistent with your information security practices.

The Query Profiler displays approximately 100,000 sampled logs at a time. It shows all the logs if 100,000 or less logs were recorded in the selected hosts and time range.

Atlas displays no more than 100,000 data points in the Query Profiler charts.

Log data is processed in batches. Data can be delayed up to five minutes from realtime.

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, the Access Tracking UI, and the Atlas Search Query Analytics UI. Downloadable log files are always complete.

Some high-latency $lookup operations don't generate a slow query log for the foreign collection. This can occur because slow query logs correspond with operations that are reported in the Query Profiler, whereas latency metrics increment only when a collection lock is acquired.

If the $lookup query on a shard can perform a local read, the $lookup doesn't record a separate operation for querying the foreign collection. A local read refers to when the query on the foreign collection targets only the same shard where the current operation is being executed. As a result, the $lookup operation increases the Namespace Insights latency metrics and operation counts, but does not generate a slow query log for the foreign collection.

To enable or disable Performance Advisor and the Query Profiler for a project, you must have the Project Owner role for the project or the Organization Owner role on its parent organization.

To view query performance in the Query Profiler, you must have Project Read Only or Project Observability Viewer access to the project.

Atlas enables the Query Profiler by default.

To disable the Query Profiler:

1

Warning

Navigation Improvements In Progress

We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview documentation.

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

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

  3. Next to the Projects menu, expand the Options menu, then click Project Settings.

    The Project Settings page displays.

2

In the Database Monitoring Tools section, toggle Performance Advisor and Profiler to Off.

The following section describes how to find slow queries using the Query Profiler.

1

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

Warning

Navigation Improvements In Progress

We're currently rolling out a new and improved navigation experience. If the following steps don't match your view in the Atlas UI, see the preview documentation.

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

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

  3. If it's not already displayed, click Clusters in the sidebar.

    The Clusters page displays.

  1. Click the View Monitoring button for the cluster.

  2. Click the Query Insights tab.

  3. Click the Query Profiler tab.

    The Query Profiler displays all your data from the log on the primary and secondary nodes by default.

2

The Query Profiler uses a scatterplot chart and a table directly below the chart to help you find slow operations.

  1. Select one or more hosts for which you want to view metrics in the Filter by Hosts dropdown.

  2. Select the time period from the Time Range or Filter by Date and Time dropdowns. The Query Profiler displays data for the last 24 hours by default.

  3. Select the metric from the Operation Execution Time dropdown. Options include:

    • Operation Execution Time (default): The total time, typically in milliseconds, that a MongoDB database operation took to complete.

    • Response Length: The size of the documents or data returned by the database in response to an operation, measured in bytes.

    • Docs Examined: The total number of documents scanned within the collection to find the results for a query.

    • Docs Returned: The number of documents that matched the query criteria that Atlas returned for the query.

    • Keys Examined: The total number of index entries scanned by the database during query execution.

    • Num Yields: The number of times an operation paused to allow other operations to proceed.

    • Docs Examined : Returned Ratio: The ratio calculated by dividing Docs Examined by Docs Returned.

    • Keys Examined : Returned Ratio: The ratio calculated by dividing Keys Examined by Docs Returned.

  4. Click the All operation types dropdown to change which operations you want to profile. The Query Profiler displays all operation types by default.

3
  • Click a scatterplot point on the chart. This opens a right-side panel with summary information.

  • Click View more details in the right-side panel to view the full query shape, detailed execution statistics, query log, and suggestions for improvement.

  • Click and drag along the X and Y axes to zoom in on a specific subset of collected data.

  • Scroll down to the table below the chart to view a list of slow queries by collection. Click a row in the table for more details.

4

When inspecting a slow query, start by looking at these key metrics and patterns:

  • Operation Execution Time (millis): Query time in milliseconds. This is the primary indicator of a slow query. If this metric is consistently high, consider optimizing the query logic, batching results, or rethink how the data is being accessed.

  • If you see "planSummary": "COLLSCAN": in the query log, the query performed a collection scan and did not use an index. This is a strong signal to add an index or rewrite the query.

  • Docs Examined (docsExamined): Number of documents MongoDB inspected for the query. If Docs Examined is significantly larger than Docs Returned, this often means that:

    • The query scanned many documents to find the results, which could impact network latency and application performance.

    • Existing indexes are inefficient or not optimal for this specific query. To learn more, see Indexes.

  • Keys Examined (keysExamined): Number of index keys scanned for the query. If this metric is 0 for a query that includes filter conditions, it's highly likely there is no index and MongoDB scanned the entire collection. This is a primary cause of slowness. If Docs Examined is very high and Keys Examined is 0 or very low compared to Docs Examined, you're likely scanning the collection or a very unselective index. To learn more, see Indexes.

  • A high Docs Examined : Returned Ratio means the query is scanning many documents to return few results, which can be a sign of an inefficient query or missing indexes.

  • Num Yields (numYields): Frequent yields suggest resource contention or long-running operations that are pausing, potentially impacting overall throughput.

  • Response Length: Unusually large response lengths indicate that queries are returning more data than necessary. Consider using projections to limit the fields returned.

  • Has Index Coverage (usedIndex): This boolean confirms whether an index was used. If set to false for a query that should be indexed, add an index.

  • If hasSort is set to true, this indicates that the query contains a sort() method. Unindexed sort() methods can be very resource intensive. Check your search index configuration and confirm whether it supports the sort() method.

Back

Query Latency

On this page