Query targeting score measures query efficiency by comparing documents read with documents returned. A score of 1 means every document read matched and appeared in the results; higher scores indicate more wasted scanning. section 21.2.1
Use the score to prioritize query-performance work:
- Treat high scores as signals to inspect index use and query structure, because unnecessary reads can increase CPU, I/O, and response time. section 21.3.1
- Use suggested-index results to find slow-query patterns; each recommendation includes an average targeting score for queries using that index. section 21.2.1
- A score of 1 represents a highly efficient pattern, but implementing an index remains an optimization opportunity rather than a guarantee. section 21.2.1
Alert on excessive scanning
Configure an Atlas alert for QUERY_TARGETING_SCANNED_OBJECTS_PER_RETURNED with GREATER_THAN and a raw threshold of 1000. The alert fires when a query scans more than 1,000 objects for each object returned, enabling proactive investigation. section 21.3.1
atlas alerts settings create --event OUTSIDE_METRIC_THRESHOLD --enabled \ --metricName QUERY_TARGETING_SCANNED_OBJECTS_PER_RETURNED \ --metricOperator GREATER_THAN --metricThreshold 1000 \ --metricUnits RAW --notificationType EMAIL --notificationEmailEnabled \ --notificationEmailAddress your-email@example.com \ --notificationIntervalMin 15
Create the metric alert with the Atlas CLI, enabling email notification and a 15-minute notification interval. section 21.3.1
atlas performanceAdvisor suggestedIndexes list \
--processName atlas-rr5vne-shard-00-00.a7niyd4.mongodb.net:27017
Retrieve suggested indexes for a selected process, then compare their average query targeting scores when investigating slow queries. section 21.2.1
