Query Targeting


Query Targeting alerts indicate inefficient queries:

  • Query Targeting: Scanned Objects / Returned occurs if the number of documents examined to fulfill a query relative to the actual number of returned documents meets or exceeds a user-defined threshold. The default is 1000, which means that a query must scan more than 1000 documents for each document returned to trigger the alert.
  • Query Targeting: Scanned / Returned occurs if the number of index keys examined to fulfill a query relative to the actual number of returned documents meets or exceeds a user-defined threshold. This alert is not enabled by default.

Ideally, the ratio of scanned documents to returned documents should be close to 1. A high ratio negatively impacts query performance. The following mongod log entry shows statistics generated from an inefficient query:

<Timestamp> COMMAND  <query>
planSummary: COLLSCAN keysExamined:0
docsExamined: 10000 cursorExhausted:1 numYields:234
nreturned:4  protocol:op_query 358ms

This query scanned 10,000 documents and returned only 4 for a ratio of 2500, which is highly inefficient. No index keys were examined, so MongoDB scanned all documents in the collection, known as a collection scan.

Viewing Query Targeting Metrics

Viewing historical metrics can help you visualize the query performance of your cluster. To view the Query Targeting charts in the Atlas UI:

  1. Click Metrics on the Clusters dashboard.
  2. On the Metrics page, click the Add Chart dropdown menu and select Query Targeting.

The Query Targeting: Scanned Objects / Returned chart displays a green line representing the number of documents examined relative to the number of returned documents for queries on the server. If the green line exceeds the user-defined threshold, Atlas generates an alert.


The query targeting alert typically occurs when there is no index to support a query or queries or when an existing index only partially supports a query or queries. Add one or more indexes to better serve the inefficient queries.

The Performance Advisor provides the easiest and quickest way to create an index. The Performance Advisor monitors queries that MongoDB considers slow and recommends indexes to improve performance. Click Create Index on a slow query for instructions on how to create the recommended index.


The Performance Advisor recognizes a query as slow if it takes longer than 100 milliseconds to execute. It is possible to receive a Query Targeting alert message for an inefficient query without receiving index suggestions from the Performance Advisor if the query takes less than 100 milliseconds to execute and the ratio of scanned to returned documents is greater than the threshold specified in the alert.

In addition, you can use the following resources to determine which query generated the alert:

  • The Real-Time Performance Panel monitors and displays current network traffic and database operations on machines hosting MongoDB in your Atlas clusters.

  • The MongoDB logs maintain an account of activity, including queries, for each mongod instance in your Atlas clusters.

  • The cursor.explain() command for the mongo shell provides performance details for all queries.

  • The Data Profiler records operations that take less than 100 ms with the data profiler.


    Enabling the Database Profiler incurs a performance overhead.

Refer to the following for more information on query performance: