MongoDB query shapes, $queryStats, profiler and index usage
Parent: Global AI Hub Research Corpus · Published reference · snapshot 2026-10-19
↓ Facts as markdownall context files
Everything the scanned sources say about MongoDB query shapes, $queryStats, profiler and index usage: 560 source-anchored units across 6 sources, grouped by facet.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Definitions
- - 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. [source]
- Query selectivity refers to how well the query predicate filters out documents in a collection. Query selectivity determines whether queries can use indexes effectively. [source]
- `queryShapeHash` is a hexadecimal string with the hash of a [query shape](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape). For details, see [Query Shapes.](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) [source]
- - Query Shape Reports are not available through the Atlas Administration API. [source]
- - `slowms` is the **previous** [slowms](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-slowms) setting. [source]
- - `sampleRate` is the **previous** [sampleRate](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-sampleRate) setting. [source]
- - `filter` is the **previous** [filter](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter) setting. [source]
- A query shape is a set of specifications that group similar queries together. Specifications can include filters, sorts, projections, aggregation pipeline stages, a namespace, and others. Queries that have similar specifications have the same query shape. [source]
- The following is an excerpt from the [`system.profile`:](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) [source]
- $queryStats groups queries with common properties into the same output document. The resulting document is called a query stats entry. [source]
- $indexStats is not allowed in transactions. [source]
Structure and components
- - If `hasSort` is set to `true`, this indicates that the query contains a [`sort()`](https://www.mongodb.com/docs/manual/reference/method/cursor.sort.md#mongodb-method-cursor.sort) method. Unindexed [`sort()`](https://www.mongodb.com/docs/manual/reference/method/cursor.sort.md#mongodb-method-cursor.sort) methods can be very resource intensive. Check your search index configuration and confirm whether it supports the [`sort()`](https://www.mongodb.com/docs/manual/reference/method/cursor.sort.md#mongodb-method-cursor.sort) method. [source]
- 2. Before creating the index, validate that no documents in the collection violate the index constraints. If a collection is distributed across shards and a shard contains a chunk with duplicate documents, the create index operation may succeed on the shards without duplicates but not on the shard with duplicates. To avoid leaving inconsistent indexes across shards, you can issue the [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) from a [`mongos`](https://www.mongodb.com/docs/manual/reference [source]
- The [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler) contains several metrics you can use to pinpoint specific inefficient queries. You can visualize up to the past 24 hours of query operations. The Query Profiler can show the Examined : Returned Ratio (index keys examined to documents returned) of logged queries, which might help you identify the queries that triggered a [`Query Targeting: Scanned / Returned`](https://www.mongodb.com/docs/atlas/reference/alert-conditions.md#mongodb-alert-Query-Targeting--Scanned---Returned) alert. The ch [source]
- The Query Profiler contains several metrics you can use to pinpoint specific inefficient queries. You can visualize up to the past 24 hours of query operations. The Query Profiler can show the Examined : Returned Ratio (index keys examined to documents returned) of logged queries, which might help you identify the queries that triggered a Query Targeting: Scanned / Returned alert. The chart shows the number of index keys examined to fulfill a query relative to the actual number of returned documents. [source]
- Query shapes exposing field names but redacted values may contain user PII (Personally Identifiable Information). To view truncated or full query shapes in Query Shape Insights, you must have one of the project roles listed above, which each give access to view PII (Personally Identifiable Information). For users without these permissions, Query Shape Insights identifies query shapes by their query shape hash. [source]
- The Query Shape Insights table contains one row for each top query shape in your project, where top query shapes are determined by highest total execution time. Each row contains the query shape or its query shape hash, the namespace of the query shape, the query command, and any metrics that you select to display. You can use the Edit Columns button to choose which of the following metrics to include as table columns: [source]
- You can also display charts for one or more of the metrics above by selecting each metric that you want to chart from the drop-down menu in the Query Shape Statistics component header. [source]
- The total number queries that performed a collection scan. The total consists of queries that did and did not use a [tailable cursor.](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) [source]
- Field values. $queryStats normalizes field values in a query to their data types (such as number or string) when the query is recorded. $queryStats never stores field values that contain user data. [source]
- $queryStats returns an array of query stats entries. Some query stats entry properties contain literal values, and some properties are normalized to group common queries. [source]
- MongoDB 9.0 updates the $queryStats output structure to improve metrics organization. [source]
- The UTC time when $queryStats read this entry from the $queryStats virtual collection. asOf does not necessarily return the same UTC time for each result. Internally, the data structure is partitioned, and each partition will be read at an individual point in time. [source]
- Contains aggregated runtime metrics associated with each query stats entry. Each query stats entry records statistics for each query that shares the same key. [source]
- Contains the query shape and additional query attributes that group a set of queries together [source]
- Contains attributes used to group similar queries together. For more information, see Query Shape. [source]
- MongoDB omits counters with a count of zero and omits subdocuments that contain no counters. If none of the recorded queries produced plan shape counters, MongoDB omits the planShapeCounters document entirely. For example, a query that matches a single document by _id uses a fast path that doesn't match any tracked plan shape, so its query stats entry contains no planShapeCounters document. [source]
- The key.queryShape document contains query shape fields. To learn about query shapes, see Query Shapes. [source]
- Query stats entries may contain a metrics.supplementalMetrics document that provides additional information about your queries. [source]
- | Document | Description | | --- | --- | | `key` | The unique combination of attributes that define an entry in the query stats output. The `key` contains attributes such as: [Query shape](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes); Client information; Read concern; [Collection type](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-collectionType) Each unique combination of attributes creates a separate entry in the `$queryStats` virtual collection. | | `asOf` | The UTC time when `$queryStats` read this [source]
- The `key.queryShape` document contains query shape fields. To learn about query shapes, see [Query Shapes.](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) [source]
- When MongoDB logs `$queryStats` output, the results are redacted and anonymized. `$queryStats` output does not contain literals or field values. [source]
- Messages related to $queryStats operations. To specify the log level for QUERYSTATS components, set the systemLog.component.queryStats.verbosity parameter. [source]
- If a command with a specific query shape is rejected, MongoDB logs a message that states the query command was rejected. The message contains the query namespace, queryShapeHash, and the command with the rejected query. MongoDB only logs the message if the log verbosity level is set to at least 2. [source]
- Messages related to [`$queryStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#mongodb-pipeline-pipe.-queryStats) operations. To specify the log level for `QUERYSTATS` components, set the [`systemLog.component.queryStats.verbosity`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-systemLog.component.queryStats.verbosity) parameter. [source]
How it works
- 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. [source]
- Percona PMM can retain index-usage metrics across restarts when the exporter is started with -collect.indexusage (not on by default); as of the 2018 post, the metrics lacked database and collection labels, so collection-level filtering was not possible. Likely outdated. [source]
- Atlas 'Query Targeting: Scanned Objects / Returned' alerts when average documents scanned divided by average documents returned, server-wide over a sampling period, exceeds a threshold. The default threshold is 1000:1 and the docs say the ideal ratio is close to 1. [source]
- When evaluating the clauses in the [`$or`](https://www.mongodb.com/docs/manual/reference/operator/query/or.md#mongodb-query-op.-or) expression, MongoDB performs a collection scan or an index scan. If all clauses are supported by indexes, MongoDB performs index scans. To use indexes to evaluate an [`$or`](https://www.mongodb.com/docs/manual/reference/operator/query/or.md#mongodb-query-op.-or) expression, all the clauses in the [`$or`](https://www.mongodb.com/docs/manual/reference/operator/query/or.md#mongodb-query-op.-or) expression must be supported by indexes. Otherwise, MongoDB performs a co [source]
- 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. [source]
- The index definitions laid out in the previous section illustrate one of the flexibility enhancements of `$search`. In order to create the `$text` index on `sample_mflix.movies`, you must first delete any existing text index on the sample data using the [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropIndex.md#mongodb-method-db.collection.dropIndex) method, as MongoDB supports only a single text index per collection. [source]
- The index only supports queries on fields included in the `wildcardProjection` object. In this example, MongoDB performs a collection scan for the following query because it includes a field that is not present in the `wildcardProjection` object: [source]
- For replica sets, run [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) on the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary). The primary stops the index build and creates an associated "abortIndexBuild" [oplog](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-oplog) entry. Secondaries which replicate the "abortIndexBuild" oplog entry stop the in-progress index build and discard the build job. See [Index Build Process](https://www.mongodb [source]
- The [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) parameter does not allow unbounded queries that use a clustered index because the queries require a full collection scan. [source]
- The notablescan parameter does not allow unbounded queries that use a clustered index because the queries require a full collection scan. [source]
- Each $indexStats result document carries name, key, host, accesses {ops, since}, spec, and shard (sharded clusters only); building appears only when true and spec.hidden only when true. accesses.ops counts user operations that used the index; accesses.since is when statistics gathering began. [source]
- Detection recipe: run $indexStats then filter accesses.ops equal to 0 (excluding _id_); treat as candidates only after a representative window. Netdata suggests at least 24h uptime under representative load and a full workload cycle if a restart happened after the since timestamp; Percona warns monthly or end-of-day reporting indexes can be missed by short windows. [source]
- 1. When a project becomes eligible, Atlas sends the first report approximately one hour after the [`Query Targeting: Scanned Objects / Returned`](https://www.mongodb.com/docs/atlas/reference/alert-conditions.md#mongodb-alert-Query-Targeting--Scanned-Objects---Returned) alert. [source]
- Turn the toggle on to subscribe or off to unsubscribe. When subscribing for the first time, select the cluster or clusters that you want the report to cover. The change applies to all [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) users in the project. [source]
- Specifies the maximum number of lock timeouts per second when trying to write to [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collections. Once this threshold is reached, profiling is disabled for this database. This setting lasts until you manually re-enable profiling. [source]
- The [default](https://www.mongodb.com/docs/atlas/configure-alerts.md#std-label-default-alert-settings) [`Query Targeting: Scanned Objects / Returned`](https://www.mongodb.com/docs/atlas/reference/alert-conditions.md#mongodb-alert-Query-Targeting--Scanned-Objects---Returned) alert ratio differs slightly. The ratio of the average number of documents scanned to the average number of documents returned during a sampling period triggers this alert. [source]
- Views are the result of aggregation pipelines. When you use $sample on a view, MongoDB appends the stage to the end of the view's aggregation pipeline syntax. Therefore, the $sample stage on a view is never the first stage and always results in a collection scan. [source]
- Because the database profiler writes data to the system.profile collection in a database, the profiler profiles some write activity, even for databases that are otherwise read-only. [source]
- When using Queryable Encryption, CRUD operations against encrypted collections are omitted from the system.profile collection. For details, see Redaction. [source]
- Atlas Infinite clusters only support this command when the [database profiler level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) is `0`. [source]
- Changes made to the profiling level with `db.setProfilingLevel()` do *not* persist. When the server restarts, it reverts to `0` (the default), or the value set by either the [`operationProfiling.mode`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-operationProfiling.mode) setting or the [`--profile`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--profile) command-line option. [source]
- - a [filter](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter) of `{ op: "query", millis: { $gt: 2000 } }`, which causes the profiler to only record `query` operations that took longer than 2 seconds. [source]
- Because the profiling level is `0`, the profiler is disabled and does not record matching operations to the profiler collection. The filter still applies to the diagnostic log. [source]
- Don't run production [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances with [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) because preventing collection scans can potentially affect queries in all databases, including administrative queries. [source]
- You can set a `filter` to control which operations are logged by the profiler. When set, any configured filters are also returned by [`db.getProfilingStatus()`](https://www.mongodb.com/docs/manual/reference/method/db.getprofilingstatus.md#mongodb-method-db.getProfilingStatus), along with a `note` explaining filter behavior. [source]
- Number of times this MongoDB process failed to store a new query stats key. Generally, these failures happen when the `$queryStats` virtual collection runs out of space. [source]
- Number of times this MongoDB process failed to compute a one-way tokenized query stats key when `$queryStats` was called with the `transformIdentifiers` option. [source]
- When set to level `2`, the profiler ignores user provided values for `slowms` and `filter`. [source]
- Because $queryStats reports only the operations that MongoDB samples, its output represents a subset of the operations run against your deployment. Counts and execution times reflect only the sampled operations. [source]
- When an HMAC key is specified to the transformIdentifiers option, $queryStats uses the HMAC key to apply an HMAC-SHA-256 hash function on the following data: [source]
- In sharded clusters, MongoDB records query statistics separately on each mongod and mongos when $queryStats is enabled. Shard servers also record statistics for queries that originate from mongos. These provide more complete shard-level metrics for queries that users route through mongos. [source]
- When Atlas runs $queryStats on your deployment, it uses a unique HMAC key per Atlas organization to transform your data and avoid collecting sensitive information. [source]
- Because the database profiler writes data to the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection in a database, the profiler profiles some write activity, even for databases that are otherwise read-only. [source]
- When using [Queryable Encryption](https://www.mongodb.com/docs/manual/core/queryable-encryption.md#std-label-qe-manual-feature-qe), CRUD operations against encrypted collections are omitted from the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection. For details, see [Redaction.](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/limitations.md#std-label-qe-redaction) [source]
- Number of times the operation had to wait for the [`acquireCount`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks.acquireCount) lock acquisitions because the locks were held in a conflicting mode. [`acquireWaitCount`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks.acquireWaitCount) is less than or equal to [`acquireCount`.](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks.acquireCount) [source]
- When MongoDB writes query profile information to the log, the [`responseLength`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.responseLength) value is in a field named `reslen`. [source]
- The following examples show the differences in log messages when `$queryStats` output is included. [source]
- The Query Profiler samples operations by using a bucketing algorithm that adjusts the sample size based on the width of the selected time range. Because of differences in bucket size, a wider time range might display fewer sampled operations than a narrower time range. For exact, unsampled operation counts, download your `mongod` logs. To learn more, see [View and Download MongoDB Logs.](https://www.mongodb.com/docs/atlas/mongodb-logs.md#std-label-mongodb-logs) [source]
- mongos performs a broadcast operation for queries that do not include the shard key, routing queries to all shards in the cluster. Some queries that do include the shard key may still result in a broadcast operation depending on the distribution of data in the cluster and the selectivity of the query. [source]
How-to and procedures
- To view query performance in the Query Profiler, you must have [`Project Read Only`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Read-Only) or [`Project Observability Viewer`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Observability-Viewer) access to the project. [source]
- To view query performance in the Query Profiler, you must have Project Read Only or Project Observability Viewer access to the project. [source]
- To change the other index options, drop the existing index with [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) before running [`db.collection.createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes) with the new options. [source]
- To drop an index, insert the index name and run [db.collection.dropIndex().](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#std-label-collection-drop-index) [source]
- To establish recommended indexes, the Performance Advisor uses these metrics in a formula to calculate the Impact, or performance improvement that creating an index matching that query shape would cause. When the Performance Advisor suggests indexes, it ranks the indexes by their Impact. The Impact is determined by the total wasted bytes read. [source]
- Use the dropIndexes command or its shell helpers dropIndex() or dropIndexes() to terminate an in-progress index build. See Stop In-Progress Index Builds for more information. [source]
- To get the index name or the index specification document for the [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) method, use the [`db.collection.getIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getindexes.md#mongodb-method-db.collection.getIndexes) method. [source]
- To drop a specific index, use the [`dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) method and specify the index name: [source]
- To drop multiple indexes, use the [`dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) method and specify an array of index names: [source]
- To drop all indexes except the `_id` index, use the [`dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) method: [source]
- To sort by a metric in descending or ascending order, click the sort icon next to the associated column name once or twice, respectively. To sort by multiple columns, press Shift and click the sort icons in the order in which you want to multi-sort the table. [source]
- 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/) [source]
- Use this endpoint to reject a query shape (preventing it from executing on the cluster) or to unreject a previously rejected query shape (allowing it to execute again). This operation is idempotent: rejecting an already rejected query shape or unrejecting an already unrejected query shape will return 200 OK. [source]
- To view more details about a query shape, click on the row for the query shape to open the Query Shape Details view. This view contains the full query shape and query shape hash, each table metric listed above, and the following additional metrics: [source]
- To view the current profiling level, see [`db.getProfilingStatus()`.](https://www.mongodb.com/docs/manual/reference/method/db.getprofilingstatus.md#mongodb-method-db.getProfilingStatus) [source]
- To clear a profile filter, run `db.setProfilingLevel()` with the `filter: "unset"` option. [source]
- To block a query shape, use an operation rejection filter. [source]
- To view metrics with Query Shape Insights, you must have Project Observability Viewer, Project Data Access Read Only, Project Data Access Read/Write, Project Data Access Admin, or Project Owner access to the project. [source]
- To run $queryStats without the transformIdentifiers option, the user must have the queryStatsRead privilege action. [source]
- To run $queryStats with the transformIdentifiers option, the user must have the both the queryStatsRead and queryStatsReadTransformed privilege actions. [source]
- To learn how to control $queryStats logging behavior, see Toggle $queryStats Log Output. [source]
- To use the MongoDB Node.js driver to add a $queryStats stage to an aggregation pipeline, use the $queryStats operator in a pipeline object. [source]
- To learn how to control `$queryStats` logging behavior, see [Toggle $queryStats Log Output.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats/toggle-logging.md#std-label-queryStats-toggle-logging) [source]
- To enable or disable Performance Advisor and the Query Profiler for a project, you must have the [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) role for the project or the [`Organization Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Organization-Owner) role on its parent organization. [source]
- 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. [source]
Examples and snippets
- ```javascript — `db.orders.aggregate( [ { $indexStats: { } } ] )` … [source]
- ```javascript — `db.salesData.dropIndex( "tenant_customFields" )` … [source]
- ```javascript — `db.<collection>.dropIndexes( [ "<index1>", "<index2>", "<index3>" ] )` … [source]
- ```javascript — `db.<collection>.dropIndexes()` … [source]
- ```javascript — `db.runCommand(` … [source]
- ```javascript — `"op" : "query",` … [source]
- ```shell — `atlas api queryShapeInsights getClusterQueryShape --version 2025-03-12 --clusterName [clusterName] --groupId 3` … [source]
- ```javascript — `db.runCommand(` … [source]
- ```javascript — `db.setProfilingLevel(<level>, <options>)` … [source]
- ```javascript — `"was" : 2,` … [source]
- ```javascript — `db.setProfilingLevel( 1, { filter: { op: "query", millis: { $gt: 2000 } } } )` … [source]
- ```javascript — `db.setProfilingLevel( 1, { filter: "unset" } )` … [source]
- ```javascript — `{ $indexStats: { } }` … [source]
- ```javascript — `db.pets.dropIndex( "catIdx" )` … [source]
- ```javascript — `db.pets.dropIndex( { "cat" : -1 } )` … [source]
- ```json — `indexStats: {` … [source]
- ```javascript — `profiler: {` … [source]
- ```javascript — `queryStats: {` … [source]
- ```javascript — `db.system.profile.find( { "command.aggregate": "movies", "command.comment" : "match_three_movies_from_1994" } ` … [source]
- ```javascript — `db.adminCommand( {` … [source]
- ```javascript — `db.getSiblingDB("admin").aggregate( [` … [source]
- ```javascript — `key: {` … [source]
- ```javascript — `db.getSiblingDB("admin").aggregate( [` … [source]
- ```javascript — `"inprog": [` … [source]
- ```javascript — `"t":{"$date":"2026-08-14T13:36:19.194-04:00"},"s":"D1",` … [source]
Measurements and reference values
- The default slowms threshold is 100 ms and default sampleRate is 1.0. slowms and sampleRate are global (all databases in the process); profiling level and filter are per database when set via db.setProfilingLevel() but process-wide when set on the command line or config file. [source]
- Profiler output goes to system.profile, a capped collection per database with a default size of 1 MB (roughly several thousand documents). To resize it, disable profiling, drop it, recreate it with db.createCollection('system.profile', {capped:true, size:N}), then re-enable profiling. [source]
- Sampling differs by version: Atlas on 8.x records up to 100 read queries/s per host and no writes; from MongoDB 9.0 $queryStats samples 1% of reads and writes by default (internalQueryStatsSampleRate, internalQueryStatsWriteCmdSampleRate, 0.0-1.0). Infrequent shapes may be missing and totals jump after an 8.x to 9.0 upgrade. [source]
- - On clusters running MongoDB 9.0 or later, Atlas randomly samples 1% of read and write operations by default. Displayed metric values reflect only sampled operations, approximately 1% of total operations. Query shapes that run infrequently may not appear in the results. This method also collects write operations (`insert`, `update`, and `delete`), which appear in Query Shape Insights alongside read operations. [source]
- In MongoDB 9.0, the default value changes from `0` to `0.01`, which enables query stats collection for read operations at a default sampling rate of 1%. [source]
- Starting in MongoDB 9.0, $queryStats collects stats for a sample of 1% of read and write operations by default. To change the sampling rate, set the internalQueryStatsSampleRate parameter for read operations or the internalQueryStatsWriteCmdSampleRate parameter for write operations. Both parameters accept a value between 0.0 and 1.0. [source]
- $queryStats stores entries in an in-memory virtual collection limited to 1% of system memory. Each entry is keyed by query shape plus client info, read concern and collection type, so one shape can produce several entries; keyHash identifies the entry and queryShapeHash groups entries by shape. [source]
Problems, failure modes and limitations
- The slow operation threshold is shared by the profiler and the diagnostic log. With logLevel 0, slow operations are logged at a rate set by slowOpSampleRate; at higher log verbosity all operations are logged regardless of latency. [source]
- Slow-query log fields have grown by version: queryFramework (6.2), cpuNanos on Linux (6.3), queues and queryShapeHash (8.0), spill metrics (8.1), originalQueryShapeHash, slow in-progress entries via slowOpInProgressThresholdMs and a deadline field (8.3), and queryKnobs (9.0). [source]
- Atlas dynamically adjusts its slow query threshold by default (used by Performance Advisor and Query Profiler); users can opt out to a fixed 100 ms and MongoDB advises against going lower. Free (M0) clusters have the managed threshold disabled and it cannot be enabled; clusters with MongoDB Search do not support it. Toggling needs Project Owner. [source]
- Since MongoDB 5.0, changes to profiler level, slowms, sampleRate or filter are written to the log file. Secondaries also log oplog applications slower than the threshold; the profiler does not capture slow oplog entries. [source]
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --clusterName | string | true | Human-readable label that identifies the cluster. | | --envelope | envelope | false | Flag that indicates whether Application wraps the response in an envelope JSON object. Some API clients cannot access the HTTP response headers or status code. To remediate this, set envelope=true in the query. Endpoints that return a list of results use the results object as an envelope. Application adds the status parameter to the response body. | | --groupId | string | true | Unique 24-hexadecimal digit str [source]
- | Field | Type | Description | | --- | --- | --- | | `createIndexes` | string | The collection for which to create indexes. | | `indexes` | array | Specifies the indexes to create. Each document in the array specifies a separate index. | | `writeConcern` | document | Optional. A document expressing the [write concern](https://www.mongodb.com/docs/manual/reference/write-concern.md). Omit to use the default write concern. | | `commitQuorum` | integer or string | Optional. The minimum number of data-bearing replica set members (i.e. commit quorum), including the primary, that must report a succes [source]
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --clusterName | string | true | Human-readable label that identifies the cluster. | | --commands | & | false | Retrieve query shape statistics matching specified MongoDB commands. To include multiple commands, pass the parameter multiple times delimited with an ampersand (&) between each command. The currently supported parameters are: find, distinct, aggregate, count, insert, update, and delete. The insert, update, and delete commands return results only for clusters running MongoDB 9.0 or later with write query shape statis [source]
- The queryShapeHash field for a query shape is also included in the slow query log when available. [source]
- This task uses [`$currentOp`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentop.md#mongodb-pipeline-pipe.-currentOp) to identify slow queries currently running on your application. To find all slow queries within a specified period, consider using a profiler. [source]
- | Field | Type | Description | | --- | --- | --- | | `getMore` | long | The cursor identifier. | | `collection` | string | The name of the collection over which the cursor is operating. | | `batchSize` | positive integer | Optional. The maximum number of documents returned for each batch. If `batchSize` is not set, `getMore` returns up to 16 mebibytes (MiB) for each batch. If `batchSize` is set, `getMore` returns the lesser of `batchSize` documents or 16 MiB. | | `maxTimeMS` | non-negative integer | Optional. Specifies how long the server waits for new documents matching a [tailable cursor](ht [source]
- | Profiler | Description | | --- | --- | | [Atlas Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler) | Provides a scatterplot chart to Atlas customers, making it easy to identify slow queries and performance outliers. | | [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) | Stores query performance information in a collection, allowing you to query MongoDB for queries with specific performance issues. | [source]
- The `ship.coordinates` field contains embedded arrays. Wildcard indexes do not record individual values of embedded arrays. Instead, they record the entire embedded array. As a result, the wildcard index cannot support a match on an embedded array value, and MongoDB fulfills the query with a collection scan. [source]
- Prevents running some collection scans when an index could be used, whether present or not. If `true`, MongoDB will not execute queries that require a collection scan and will return an error. Exclusions include queries without filters and queries against capped collections, such as the oplog. [source]
- Index errors found during the collection scan phase, except duplicate key errors, are returned immediately and then the index build stops. Earlier MongoDB versions return errors in the commit phase, which occurs near the end of the index build. MongoDB 7.1 helps you to rapidly diagnose index errors. For example, if an incompatible index value format is found, the error is returned to you immediately. [source]
- | Output Field | Description | | --- | --- | | `name` | Index name. | | [key](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#std-label-indexStats-output-key) | Index key specification. See also: [spec.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#std-label-indexStats-output-spec) | | [host](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#std-label-indexStats-output-host) | The hostname and port of the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-b [source]
- | Metrics | Deployment metrics provide insight into hardware performance and database operation efficiency. Atlas collects metrics for your servers, databases, and MongoDB processes and stores metrics data at [various granularity levels](https://www.mongodb.com/docs/atlas/monitor-cluster-metrics/#premium-monitoring-granularity). For each granularity level, Atlas computes metrics as averages of the reported metrics at the next finer granularity level. Many metrics have a burst reporting equivalent. You can monitor metrics in the Atlas UI using the Metrics view, Real-Time Performance Panel, Quer [source]
- The Query Profiler identifies slow queries and bottlenecks, and suggests index refinement and query restructuring to improve the performance of your database. It provides visibility into the slowest operations over up to seven days in the Atlas UI, making it easier to identify trends and outliers in query efficiency. We recommend that you use this data to pinpoint and troubleshoot poorly performing queries, reducing performance overhead. [source]
- The Performance Advisor automatically analyzes logs for slow-running queries and recommends indexes to create and drop. It analyzes slow queries and provides index suggestions for individual collections, ranked by a calculated impact score, and tailored to your workload. This gives you an easy, instantaneous way to make high-impact performance improvements. We recommend that you monitor regularly, focus on slow queries, and enable the profiler selectively to minimize overhead. [source]
- - You cannot specify [`db.collection.dropIndex("*")`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) to drop all non-`_id` indexes. Use [`db.collection.dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) instead. [source]
- | Parameter | Type | Description | | --- | --- | --- | | `index` | string or document | Required. Specifies the index to drop. You can specify the index either by the index name or by the index specification document. To drop a [text](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-type-text) index, specify the index name. You cannot specify `"*"` to drop all non-`_id` indexes. Use [`db.collection.dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) instead. If an i [source]
- You can use [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) to drop existing indexes on the same collection even if there is a build in progress on another index. In earlier versions, attempting to drop a different index during an in-progress index build results in a `BackgroundOperationInProgressForNamespace` error. [source]
- Starting in MongoDB 6.0, [`dropIndexes`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) raises an error if you attempt to use it to remove the last remaining shard key compatible index. Passing `"*"` to [`dropIndexes`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) drops all indexes except the `_id` index and the last remaining shard key compatible index, if one exists. [source]
- If you restart the `mongod` as a standalone (that is, removing or commenting out [`replication.replSetName`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-replication.replSetName) or omitting [`--replSetName`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--replSet)), the `mongod` cannot restart the index build. The build remains in a paused state until it is manually [`dropped`.](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) [source]
- | Stage | Description | | --- | --- | | Lock | The `mongod` obtains an exclusive `X` lock on the the collection being indexed. This blocks all read and write operations on the collection, including the application of any replicated write operations or metadata commands that target the collection. The `mongod` does not yield this lock. | | Initialization | The `mongod` creates three data structures at this initial state: The initial index metadata entry.; A temporary table ("side writes table") that stores keys generated from writes to the collection being indexed during the build process.; A t [source]
- [`hasSortStage`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.hasSortStage) is a boolean that is `true` when a query **cannot** use the ordering in the index to return the requested sorted results; i.e. MongoDB must sort the documents after it receives the documents from a cursor. The field only appears when the value is `true`. [source]
- WARNING: The accesses field reports index usage metrics only for the node where the query runs. For more comprehensive index usage statistics, run $indexStats on each node in the cluster. [source]
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --duration | int | false | Length of time in milliseconds for which you want to return results. If you specify the since option, the duration starts at the date and time specified. If you don't set the since option, this command returns data from the duration before the current time. | | -h, --help | | false | help for list | | --nLog | int | false | Maximum number of log lines to return. This value defaults to 20000. | | --namespaces | strings | false | Namespaces from which to retrieve suggested slow query logs formatted a [source]
- Slow operations are logged based on `workingMillis`, which is the amount of time that MongoDB spends working on that operation. This means that factors such as waiting for locks and flow control do not affect whether an operation exceeds the slow operation threshold. [source]
- When [`logLevel`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.logLevel) is set to `0`, MongoDB records *slow* operations to the diagnostic log at a rate determined by [`slowOpSampleRate`.](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-operationProfiling.slowOpSampleRate) [source]
- At higher `logLevel` settings, all operations appear in the diagnostic log regardless of their latency with the following exception: the logging of slow oplog entry messages by the secondaries. The secondaries log only the slow oplog entries; increasing the `logLevel` does not log all oplog entries. [source]
- The slow operation time threshold for an in-progress query, in milliseconds. MongoDB logs operations that run for longer than this threshold as slow in-progess queries. MongoDB logs a query as a slow in-progress query as soon as the query operation crosses the time threshold. [source]
- The fraction of *slow* operations that should be profiled or logged. [`--slowOpSampleRate`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--slowOpSampleRate) accepts values between 0 and 1, inclusive. [source]
- [`--slowOpSampleRate`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--slowOpSampleRate) does not affect the slow oplog entry logging by the secondary members of a replica set. Secondary members log all oplog entries that take longer than the slow operation threshold regardless of the [`--slowOpSampleRate`.](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--slowOpSampleRate) [source]
- | Field | Type | Literal or Normalized | | --- | --- | --- | | `key.queryShape.filter` | Document | Normalized | | `key.queryShape.sort` | Document | Literal | | `key.queryShape.projection` | Document | Normalized | | `key.queryShape.skip` | Integer | Normalized | | `key.queryShape.limit` | Integer | Normalized | | `key.queryShape.singleBatch` | Boolean | Literal | | `key.queryShape.max` | Document | Normalized | | `key.queryShape.min` | Document | Normalized | | `key.queryShape.returnKey` | Boolean | Literal | | `key.queryShape.showRecordId` | Boolean | Literal | | `key.queryShape.tailable` | [source]
- | Field | Type | Literal or Normalized | | --- | --- | --- | | `key.queryShape.collation` | Document | Normalized | | `key.queryShape.query` | Document | Normalized | | `key.queryShape.limit` | Integer | Normalized | | `key.queryShape.skip` | Integer | Normalized | [source]
- `key.queryShape.limit` reflects the `limit` field of the delete statement, where `0` deletes all matching documents and `1` deletes a single document. It does not cap the number of query stats entries. [source]
- | Field | Type | Literal or Normalized | | --- | --- | --- | | `key.queryShape.q` | Document | Normalized | | `key.queryShape.limit` | Integer | Literal | | `key.queryShape.let` | Document | Normalized | | `key.queryShape.collation` | Document | Literal | [source]
- - 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. [source]
- - Response Length: Unusually large response lengths indicate that queries are returning more data than necessary. Consider using [projections](https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results.md#std-label-projections) to limit the fields returned. [source]
- $queryStats must run on the admin database as the first pipeline stage, cannot target a single collection, and needs the queryStatsRead privilege (queryStatsReadTransformed too when using transformIdentifiers); clusterMonitor grants both. [source]
- Historical bugs: $queryStats on mongos could fail if the stats store did not fit in memory because the sort could not spill (SERVER-93832, fixed 8.0.4/8.1.0-rc0); memory mis-accounting in the store was fixed in 7.3.0-rc0 (SERVER-84298). [source]
- This endpoint only returns query shapes with REJECTED status. If the specified query shape hash does not correspond to a rejected query shape, a 404 Not Found error is returned. [source]
- - [profiler log messages](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) and [diagnostic log messages (i.e. mongod/mongos log messages)](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref) when logging slow queries. [source]
- These operations are also included in the logging of slow queries. See slowOpThresholdMs for more information about slow query logging. [source]
- You can monitor operation-level query execution metrics for [query shapes](https://www.mongodb.com/docs/manual/core/query-shapes/) with slow-running queries using Query Shape Insights. The Query Shape Insights page displays charts and a table that describe the performance metrics for the query shapes in your project with the highest total execution time. You can filter the displayed query shape data by host, shard, and time range, and select up to five query shapes to visualize in the corresponding metric charts. [source]
- Query Shape Insights displays charts and a table that describe metrics for query shapes in your project with slow-running queries. [source]
- Atlas can send you a Query Shape Report email that summarizes inefficient query shapes for a cluster in your project. To help you identify and investigate slow queries, the report links directly to the Query Shape Insights page. [source]
- Some high-latency [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) operations may not generate a slow query log for the foreign collection. This can occur because slow query logs correspond with operations that are reported in the [database profiler](https://www.mongodb.com/docs/manual/reference/database-profiler.md#std-label-profiler), whereas latency metrics increment only when a [collection lock](https://www.mongodb.com/docs/manual/faq/concurrency.md#std-label-faq-concurrency-locking) is acquired. [source]
- 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 `$collStats` latency metrics and operation counts, but does not generate a slow query log for the foreign collection. [source]
- For a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance, the command enables, disables, or configures the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler). The profiler captures and records data on the performance of write operations, cursors, and database commands on a running [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instance. If the profiler is disabled, the command configures how slow operations [source]
- For a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance, the command only configures how operations get written to the diagnostic log. You cannot enable the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance because `mongos` does not have any collections that the profiler can write to. [source]
- | Field | Type | Description | | --- | --- | --- | | `profile` | int | Configures the profiler level. The following profiler levels are available: `0`The profiler is off and does not collect any data. This is the default profiler level.`1`The profiler collects data for operations that exceed the `slowms` threshold or match a specified [filter.](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter)When a filter is set:The `slowms` and `sampleRate` options are not used for profiling.; The profiler only captures operations that [source]
- With [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instances, the method sets the `slowms`, `sampleRate` and `filter` configuration settings, which configure how operations get written to the diagnostic log. You cannot enable the [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md) on a [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance because `mongos` does not have any collections that the profiler can write to. The `profile` level m [source]
- | Log Message | Description | | --- | --- | | Accepted TLS connection from peer | Indicates that the server successfully parsed the peer certificate during the TLS handshake with an accepted ingress connection. | | Ingress TLS handshake complete | Indicates that the TLS handshake with an ingress connection is complete. | | Hello completed | Indicates that the initial connection handshake completed on an incoming client connection. MongoDB displays the log message only with the first `hello` command. | | Auth metrics report | Specifies the completion of a step in the authentication conversation [source]
- In rare circumstances, a write can fail due to cache pressure. When this happens MongoDB issues a `TemporarilyUnavailable` error and increments the `temporarilyUnavailableErrors` counter in two places: the slow query log and the [Full Time Diagnostic Data Capture (FTDC).](https://www.mongodb.com/docs/manual/administration/full-time-diagnostic-data-capture.md#std-label-ftdc-stub) [source]
- - [atlas api performanceAdvisor listSlowQueryLogs](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-performanceadvisor-listslowquerylogs.md#std-label-atlas-api-performanceAdvisor-listSlowQueryLogs) - Returns log lines for slow queries that the Performance Advisor and Query Profiler identified. [source]
- The slow operation threshold determines which operations are flagged by the Performance Advisor and Query Profiler. When enabled, the application uses the average execution time for operations on your cluster to determine slow-running queries. As a result, the threshold is more pertinent to your cluster workload. Application-managed slow operation threshold is enabled by default for dedicated clusters (M10+). [source]
- Returns log lines for slow queries that the Performance Advisor and Query Profiler identified. [source]
- | Name | Type | Required | Description | | --- | --- | --- | --- | | --duration | int | false | Length of time expressed during which the query finds slow queries among the managed namespaces in the cluster. This parameter expresses its value in milliseconds. If you don't specify the **since** parameter, the endpoint returns data covering the duration before the current time.; If you specify neither the **duration** nor **since** parameters, the endpoint returns data from the previous 24 hours. | | --envelope | envelope | false | Flag that indicates whether Application wraps the response in an [source]
- If the mongod encounters a key generation error while generating a key during the collection scan, it stores that key in the constraint violation table for later processing. [source]
- You can return log lines for slow queries that the Query Profiler identifies from the Atlas Administration API with [Return Slow Queries.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listslowqueries) [source]
- [Query Shape Insights](https://www.mongodb.com/docs/atlas/query-shape-insights.md#std-label-query-shape-insights) displays performance statistics for query shapes with slow-running queries. You can select up to five query shapes to view their metrics in charts, and filter by host, shard, and time range to monitor the most relevant performance metrics and statistics for your project. [source]
- The [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler) displays slow-running operations and their key performance statistics. You can explore a sample of historical queries for up to the last seven days without additional cost or performance overhead. Before you enable the Query Profiler, see [Considerations.](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-atlas-considerations-profile-database) [source]
- Collection scans indicate that the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) had to scan the entire collection document by document to identify the results. This is a generally expensive operation and can result in slow queries. [source]
- Collection scans indicate that the mongod had to scan the entire collection document by document to identify the results. This is a generally expensive operation and can result in slow queries. [source]
- - In general, you should use [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) only when you cannot express your query using another operator. If you must use [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where), try to include at least one other standard query operator to filter the result set. Using [`$where`](https://www.mongodb.com/docs/manual/reference/operator/query/where.md#mongodb-query-op.-where) alone requires a collection scan. [source]
- The profiler does not capture slow oplog entries. [source]
- You cannot run $queryStats on a specific collection. For complete examples, see Examples. [source]
- Statistics for the $queryStats stage are tracked in a virtual collection that is stored in-memory. The memory limit for the virtual collection is 1% of the system's total memory. [source]
- Pattern names describe plans at a coarse level. They omit limit and skip stages, and they don't distinguish whether a stage applies a filter or which type of projection a plan uses. To determine those details, combine a pattern counter with the nodes counters and the query shape for the entry. [source]
- The slow operation threshold determines which operations are flagged by the Performance Advisor and Query Profiler. When disabled, the application considers any operation that takes longer than 100 milliseconds to be slow. [source]
- You cannot run `$queryStats` on a specific collection. For complete examples, see [Examples.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-examples) [source]
- These operations are also included in the logging of slow queries. See [`slowOpThresholdMs`](https://www.mongodb.com/docs/manual/reference/configuration-options.md#mongodb-setting-operationProfiling.slowOpThresholdMs) for more information about slow query logging. [source]
- The threshold determines which operations the Performance Advisor and Query Profiler considers slow. When enabled, MongoDB Cloud uses the average execution time for operations on your cluster to determine slow-running queries. As a result, the threshold is more pertinent to your cluster workload. The slow operation threshold is enabled by default for dedicated clusters (M10+). When disabled, MongoDB Cloud considers any operation that takes longer than 100 milliseconds to be slow. [source]
- The length in bytes of the operation's result document. A large [`responseLength`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.responseLength) can affect performance. To limit the size of the result document for a query operation, you can use any of the following: [source]
- | Notification Option | Description | | --- | --- | | Atlas Project | Sends the alert by email or text message to users with specific roles in the Project. Atlas Project is the default alert recipient. You can configure the roles the alert is sent to and how it's delivered. You can't add a second Atlas Project as the recipient. If the [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) role is assigned to a human project member, Atlas delivers alerts to that member's configured email address or SMS target. If the [`Project Owner`](https: [source]
- | Notification Option | Service Account Alerts | User Alerts | Billing Alerts | Description | | --- | --- | --- | --- | --- | | Atlas Organization | | | | Sends the alert by email or text message to users with specific roles in the Organization. Select the Organization roles that should receive the alerts from the Select Role(s) check boxes or select All Roles for all users in the Organization to receive the alert.; Select SMS to send these alerts to the mobile number configured for each Atlas Organization user in their Account page.; Select Email to send these alerts to the email address c [source]
- Slow operation log messages and database profiler entries include a cpuNanos field that specifies the total CPU time spent by a query operation in nanoseconds. The cpuNanos field is only available on Linux systems. [source]
- The totalOplogSlotDurationMicros in the slow query log message shows the time between a write operation getting a commit timestamp to commit the storage engine writes and actually committing. mongod supports parallel writes. However, it commits write operations with commit timestamps in any order. [source]
- MongoDB 8.3 also introduces slow in-progress query log entries. Queries trigger a slow-in progress log during execution. These logs contain less information than standard slow query logs. MongoDB logs queries at most once if the query's duration surpasses the operationProfiling.slowOpInProgressThresholdMs. [source]
- When an operation specifies a time limit for a query, slow query logs contain a deadline field. deadline indicates the time the operation must complete by, which is equal to the time at the start of the operation plus the value of the query timeout. [source]
- Starting in MongoDB 5.0, log messages for slow queries include a system.profile.authorization section. These metrics help determine if a request is delayed because of contention for the user authorization cache. [source]
- The [profiler entries](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) and the [diagnostic log messages (i.e. mongod/mongos logmessages)](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-message-slow-ops) for read/write operations include: [source]
- The CRUD operations below are omitted from the [slow operations](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-message-slow-ops) query log and the [Database Profiler](https://www.mongodb.com/docs/manual/reference/database-profiler.md#std-label-profiler) `system.profile` collection when you run them on an encrypted collection. [source]
- The Query Profiler diagnoses and monitors performance issues. This monitoring can expose slow-running queries and their key performance statistics in the Atlas UI. [source]
- Atlas collects and displays statistics from any of your [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances. The Query Profiler stores your `mongod` query [log data](https://www.mongodb.com/docs/atlas/mongodb-logs.md#std-label-mongodb-logs), which can be accessed directly through the Query Profiler or through the Atlas CLI, and use it to identify slow queries. Atlas displays this data on the Query Insights page, in the Query Profiler tab of an instance. [source]
- The Atlas Query Profiler shows operations across your entire cluster by default. You can filter the Query Profiler view to only operations coming from specified hosts 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 option in the Cluster sidebar displays information to reveal slow database operations over a set time frame, such as the following: [source]
- 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`](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md#mongodb-method-db.setProfilingLevel) [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) command. [source]
- Changing the threshold for slow operations using [`db.setProfilingLevel`](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md#mongodb-method-db.setProfilingLevel) can impact performance and system log settings. Carefully consider any performance and security implications before you use [`db.setProfilingLevel`](https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel.md#mongodb-method-db.setProfilingLevel) to adjust the Query Profiler settings on a production deployment. Query Profiler settings reset to default values following a node restart. [source]
- The following section describes how to find slow queries using the Query Profiler. [source]
- The Query Profiler uses a scatterplot chart and a table directly below the chart to help you find slow operations. [source]
- 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. [source]
- 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. [source]
- Find Slow Queries with the Query Profiler [source]
Comparisons and alternatives
- | Field | Type | Description | | --- | --- | --- | | dropIndexes | String | The name of the collection whose indexes to drop. | | index | string or document or array of strings | The index or indexes to drop. To drop all indexes except the `_id` index and the last remaining shard key index from the collection if one exists, specify `"*"`.; To drop a single index, specify either the index name, the index specification document (unless the index is a [text](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-type-text) index), or an array of the index name. [source]
- 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 [source]
- If the slow query log contains consecutive $match stages in the aggregation pipeline, the two stages can coalesce into the first $match stage and result in a single $match stage. As a result, the query shape in the Performance Advisor might differ from the actual query you ran. [source]
- Number of times a collection scan occurred during query execution. During a collection scan, each document in a collection is compared to the query predicate. Collection scans occur if no appropriate [index](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) exists that [covers](https://www.mongodb.com/docs/manual/core/query-optimization.md#std-label-indexes-covered-queries) the query. [source]
- A 1:1 docs-examined to returned ratio does not prove an index is cheap. Pythian's index {certificate_number, address.zip, date} had docs examined equal to returned but over 40k keys examined, and execution time rose 10% versus no index, because the range field came first and the zip filter ran after the fetch. [source]
- | Chart/Location | Description | | --- | --- | | Connections, Network In, Network Out (Top of panel) | Displays the number of current connections to the machine hosting MongoDB and the number of inbound and outbound bytes as reported by [`mongostat`.](https://www.mongodb.com/docs/database-tools/mongostat.md#mongodb-binary-bin.mongostat) | | CPU, Disk IOPS, and Sys Mem (Top of panel) | Displays the currently used percentage of CPU, disk read and write operations per second, and the total physical memory usage, excluding buffers and swap space, of the machine hosting MongoDB. | | Operations | Di [source]
- | Behavior Starting in MongoDB 7.1 | Behavior in Earlier MongoDB Versions | | --- | --- | | Index errors found during the collection scan phase, except duplicate key errors, are returned immediately and then the index build stops. Earlier MongoDB versions return errors in the commit phase, which occurs near the end of the index build. MongoDB 7.1 helps you to rapidly diagnose index errors. For example, if an incompatible index value format is found, the error is returned to you immediately. | Index build errors can take a long time to be returned compared to MongoDB 7.1 because the errors are [source]
- Starting in MongoDB 8.3, [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) is idempotent. If you specify an index that does not exist, [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) ignores the non-existent index and completes successfully instead of returning an `IndexNotFound` error. In earlier versions, [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.col [source]
- The docs state queryShapeHash is derived from the shape itself and is expected to be identical on every node and on replica sets vs sharded clusters in current versions, but advise verifying before reusing it across clusters, versions or after migration. [source]
- Starting in MongoDB 9.0, you can use the `queryKnobs` setting to override internal server parameters for a single [query shape](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) instead of the whole instance. Set the `queryKnobs` field for targeted queries to mitigate the impact of one regressed shape without changing behavior for other workloads on the same deployment. [source]
- For example, you can override the [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) server parameter for a single query shape instead of the whole instance by setting `queryKnobs` to `{ noTableScan: true }`. [source]
- Unlike [`setParameter`](https://www.mongodb.com/docs/manual/reference/command/setparameter.md#mongodb-dbcommand-dbcmd.setParameter), which applies per process and can differ between nodes, MongoDB applies the same `queryKnobs` values across the whole cluster for the matching query shape. [source]
- - The Atlas [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler) records operations that Atlas considers slow when compared to average execution time for all operations on your cluster. [source]
- The Query Profiler differs from the [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-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](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler/#profiling-levels). Changing the profiling level doesn't impact the slow queries displayed in the Query Profiler. [source]
- | Field | Type | Description | | --- | --- | --- | | `resumeAfter` | document | Optional. Directs [`watch()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.watch.md#mongodb-method-db.collection.watch) to attempt resuming notifications starting after the operation specified in the resume token. Each change stream event document includes a resume token as the `_id` field. Pass the *entire* `_id` field of the change event document that represents the operation you want to resume after. `resumeAfter` is mutually exclusive with `startAfter` and `startAtOperationTime`. | | `star [source]
- The Atlas Query Profiler records operations that Atlas considers slow when compared to average execution time for all operations on your cluster. [source]
- Atlas Query Shape Insights (M10+, MongoDB 8.0+) ranks shapes by total execution time, filterable by host/shard over 7 days; users without PII-viewing roles see only the queryShapeHash instead of the shape. [source]
Facts and statements
- This metric **does not** reflect the MongoDB Search index usage. [source]
- - Click View more details in the right-side panel to view the full query shape, detailed execution statistics, query log, and suggestions for improvement. [source]
- Profiler level 0 is off, level 1 records operations slower than slowms (or matching a filter), and level 2 records all operations; at level 2 the profiler ignores user-supplied slowms and filter values. [source]
- If a profiling filter is set, slowms and sampleRate no longer apply to the profiler or the diagnostic log. A filter such as { op: 'query', millis: { $gt: 2000 } } controls which operations are profiled and logged. [source]
- MongoDB warns the profiler can degrade performance and disk use, especially at level 2 or with a low slowms at level 1, and points to Atlas Query Profiler / Performance Advisor as alternatives. Blogs advise level 1 with a tuned slowms and a lowered sampleRate on busy systems; avoid level 2 in production. [source]
- system.profile.queryShapeHash [source]
- system.profile.planSummary [source]
- - Num Yields (`numYields`): Frequent yields suggest resource contention or long-running operations that are pausing, potentially impacting overall throughput. [source]
- - Performs a collection scan. [source]
- | 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 | Aver [source]
- The Performance Advisor also shows each executed sample query that matches the query shape, with specific metrics for that query. [source]
- The Performance Advisor monitors queries that take longer than `100` milliseconds to execute and groups these queries into common [query shapes](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape). The Performance Advisor calculates the inefficiency of each query shape by considering the following aggregated metrics from queries which match the shape: [source]
- The total number of indexes. [source]
- A document that reports observability metrics for multikey path changes on both ordinary indexes and [wildcard indexes.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard.md#std-label-wildcard-index-core) [source]
- The number of new multikey metadata paths recorded for ordinary indexes while recording the path during a multi-document transaction. [source]
- The number of new multikey metadata paths recorded for ordinary indexes while recording the path outside a multi-document transaction. [source]
- The number of new multikey metadata paths recorded for [wildcard indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard.md#std-label-wildcard-index-core) while recording the path during a multi-document transaction. [source]
- The number of new multikey metadata paths recorded for [wildcard indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard.md#std-label-wildcard-index-core) while recording the path outside a multi-document transaction. [source]
- The number of side transactions used to record multikey path changes for ordinary indexes. [source]
- ```javascript db.siteAnalytics.dropIndex( { "url_1" } ) ``` [source]
- ```javascript db.siteAnalytics.dropIndex( { "url_1_dummyField_1" } ) ``` [source]
- An index is unused if it doesn't support any queries. [source]
- The Performance Advisor flags an index as unused if it hasn't supported a query in 7 or more days after it was created or the server was restarted. [source]
- - Keys Examined: The total number of index entries scanned by the database during query execution. [source]
- - Existing indexes are inefficient or not optimal for this specific query. To learn more, see [Indexes.](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) [source]
- - Uses Index (`usedIndex`): This boolean confirms whether a MongoDB index was used. If set to `false` for a query that should be indexed, add an [index.](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) [source]
- $indexStats takes an empty document ({ $indexStats: {} }), must be the first stage of an aggregation pipeline, is not allowed in transactions, and with access control requires at least the clusterMonitor role. [source]
- accesses reports usage only for the node where the query runs, and only user-driven access. TTL-index deletions and chunk split/migration operations do not increment ops. MongoDB documents say to run $indexStats on each node for comprehensive stats. [source]
- Zero ops can be a false negative for unique indexes: a uniqueness check on insert does not increment the ops counter, so an unused-for-reads unique index still enforces a constraint and must not be dropped on stats alone. [source]
- system.profile.authorization is not included in db.currentOp() output. [source]
- The following aggregation operation finds movies created in 1994 and includes the `comment` option to provide tracking information in the `logs`, the `db.system.profile` collection, and `db.currentOp`. [source]
- [`db.currentOp()`](https://www.mongodb.com/docs/manual/reference/method/db.currentop.md#mongodb-method-db.currentOp) and the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) report the same basic diagnostic information for all CRUD operations, including the following: [source]
- | Field | Description | | --- | --- | | `"$ownOps"` | Boolean. If set to `true`, returns information on the current user's operations only. On [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) instances, users are always authorized to run `currentOp` with `"$ownOps": true` to view their own operations. See [access control.](https://www.mongodb.com/docs/manual/reference/command/currentop.md#std-label-currentOp-access-control) | | `"$all"` | Boolean. If set to `true`, returns information on all operations, including operations on idle connectio [source]
- Percona treats the gap between examined and returned counts as the signal: 325 docs examined for 6 returned, and 2517 examined for 493 returned, are called not optimal. A better compound index brings examined equal to returned. [source]
- Atlas also offers 'Query Targeting: Scanned / Returned', which counts index keys examined relative to documents returned against a user-defined threshold. It is not enabled by default. [source]
- Percona's rule for field order in a compound index is most selective field first; it gives no formal selectivity definition or numeric threshold. MongoDB's docs example instead shows equality-before-range ordering winning, so selectivity alone is not the ordering rule. [source]
- 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) [source]
- Atlas might not [log](https://www.mongodb.com/docs/atlas/mongodb-logs.md#std-label-mongodb-logs) the individual operations that contribute to the Query Targeting ratios due to automatically set thresholds. However, you can still use the Query Profiler and Query Targeting metrics to analyze and optimize query performance. [source]
- You can also monitor collection-level query latency with Namespace Insights and query performance with the Query Profiler. [source]
- Atlas might not log the individual operations that contribute to the Query Targeting ratios due to automatically set thresholds. However, you can still use the Query Profiler and Query Targeting metrics to analyze and optimize query performance. [source]
- Monitor Query Performance with the Query Profiler [source]
- Collation options on an existing index can be updated. To change other index options, drop the existing index with db.collection.dropIndex() then run createIndexes with the new options. [source]
- | Metric | Description | | --- | --- | | Total Execution Time | Total time in microseconds spent running queries with the given query shape. If the query resulted in [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getMore.md#mongodb-dbcommand-dbcmd.getMore) commands, this metric includes the time spent processing the [`getMore`](https://www.mongodb.com/docs/manual/reference/command/getMore.md#mongodb-dbcommand-dbcmd.getMore) requests. This metric does not include time spent waiting for the client. | | Avg Execution Time | Average time in microseconds spent running queries wit [source]
- [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) reports index usage metrics in the [accesses](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#std-label-indexStats-output-accesses) field only for the node where the query runs. For more comprehensive index usage statistics, run [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) on each node in the cluster. [source]
- Unhiding a hidden index resets its [`$indexStats`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) [source]
- 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: [source]
- The type of query operation in the query shape affects the order of the fields used to construct the index. In general, the Performance Advisor ranks fields by their [cardinality.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-cardinality) [source]
- Once the mongod completes the collection scan, it dumps the sorted keys into the index. [source]
- The statistics reported by the [accesses](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#std-label-indexStats-output-accesses) field only apply to the node where the query is being run and only include index access driven by user requests. It does not include internal operations like deletion via [TTL indexes](https://www.mongodb.com/docs/manual/core/index-ttl.md#std-label-index-feature-ttl) or chunk split and migration operations. [source]
- Hiding an unhidden index resets its $indexStats. [source]
- If an index specified to [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) is still building, [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) attempts to stop the in-progress build. Stopping an index build has the same effect as dropping the built index. [source]
- The `dropIndex` command returns the number of indexes in the collection prior to the command being run, and indicates whether the command was successful: [source]
- The [`dropIndexes`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) command drops one or more indexes (except the index on the `_id` field and the last remaining shard key index, if one exists) from the specified collection. [source]
- Starting in MongoDB 8.3, if an array of index names includes a non-existent index, [`dropIndexes`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) ignores the non-existent index and drops the remaining specified indexes. [source]
- ```javascript db.runCommand( { dropIndexes: "collection", index: "*" } ) ``` [source]
- ```javascript db.runCommand( { dropIndexes: "collection", index: "age_1" }) ``` [source]
- ```javascript db.runCommand( { dropIndexes: "collection", index: [ "age_1", "age_1_status_1" ] } ) ``` [source]
- | Method | Description | | --- | --- | | [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) | Drops a specific index from the collection. | | [`db.collection.dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) | Drops all removable indexes from the collection or an array of indexes, if specified. | [source]
- A document that reports statistics on all indexes on databases and collections in non-system namespaces only. `indexStats` does not report statistics on indexes in the `admin`, `local`, and `config` databases. [source]
- A document that provides counters for each index type and the number of accesses on each index. Each index type under `indexStats.features` has a `count` field that counts the total number of indexes for that type, and an `accesses` field that counts the number of accesses on that index. [source]
- Total number of in-bounds and out-of-bounds index keys examined by queries with the given query shape. [source]
- Ratio of in-bounds and out-of-bounds index keys examined to indexes containing documents returned by queries with the given query shape. [source]
- Total number of index keys inserted by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Total number of index keys deleted by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- The type of query operation in the query shape affects the order of the fields used to construct the index. In general, the Performance Advisor ranks fields by their cardinality. [source]
- 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.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-collection-scan) [source]
- Collection scans, counted separately based on whether the scan uses the clustered index. [source]
- The Data Explorer only shows Usage metrics for the primary node in your cluster. If your application primarily reads from secondary nodes, the Usage metrics do not fully reflect index usage across your cluster. [source]
- The Performance Advisor inspects only the 20 most active collections for unused indexes. [source]
- For case sensitive regular expression queries, if an index exists for the field, then MongoDB matches the regular expression for the values in the index. This can be faster than a collection scan. [source]
- Indicates the query performed a full collection scan. To correct this, [Create an Index.](https://www.mongodb.com/docs/manual/core/indexes/create-index.md#std-label-manual-create-an-index) [source]
- - Hidden indexes are updated upon write operations to the collection and continue to consume disk space and memory. As such, they are included in various statistics operations, such as [`db.collection.stats()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.stats.md#mongodb-method-db.collection.stats) and [`$indexStats`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) [source]
- - Hiding an unhidden index or unhiding a hidden index resets its [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats). Hiding an already hidden index or unhiding an already unhidden index does not reset the [`$indexStats`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) [source]
- Hidden indexes are updated upon write operations to the collection and continue to consume disk space and memory. As such, they are included in various statistics operations, such as db.collection.stats() and $indexStats. [source]
- As an alternative, you can [`drop`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) any misconfigured TTL indexes and recreate them later using the [`createIndexes`](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#mongodb-dbcommand-dbcmd.createIndexes) command. [source]
- Index statistics reset on mongod restart, on index drop and recreation, and on any collMod modification of the index. Hiding an unhidden index also resets its $indexStats, so a hide-then-measure window starts at the hide time. [source]
- On sharded clusters $indexStats is local to each shard primary and a mongos does not aggregate it; an index can show zero on one shard and serve queries on another, so sum accesses.ops across all shards before calling an index unused (Netdata's guide; MongoDB docs state the per-node scope). [source]
- - A link to the report subscription settings in Project Settings. To learn more, see [Manage Project Settings.](https://www.mongodb.com/docs/atlas/tutorial/manage-project-settings.md#std-label-project-settings) [source]
- The following example sets for a [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) or [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) instance: [source]
- The maximum number of milliseconds to wait for a lock acquisition before performing writes to [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collections. [source]
- You can specify the amount of time to wait before abandoning writes to [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collections by setting the [`internalQueryGlobalProfilingLockDeadlineMs`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.internalQueryGlobalProfilingLockDeadlineMs) parameter. [source]
- - Parameter names such as the `partitionBy` parameter in [`$setWindowFields`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/setwindowfields.md#mongodb-pipeline-pipe.-setWindowFields) [source]
- | Field | Type | Literal or Normalized | | --- | --- | --- | | `key.queryShape.collation` | Document | Normalized | | `key.queryShape.key` | String | Literal | | `key.queryShape.query` | Document | Normalized | [source]
- | Field | Type | Literal or Normalized | | --- | --- | --- | | `key.queryShape.q` | Document | Normalized | | `key.queryShape.u` | Document or Array | Normalized | | `key.queryShape.c` | Document | Normalized | | `key.queryShape.arrayFilters` | Array of documents | Normalized | | `key.queryShape.multi` | Boolean | Literal | | `key.queryShape.upsert` | Boolean | Literal | | `key.queryShape.let` | Document | Normalized | | `key.queryShape.collation` | Document | Literal | [source]
- $queryStats normalises literal values to types (e.g. {item:'card'} becomes {item:'?string'}) but keeps readConcern/readPreference literal. With transformIdentifiers (algorithm hmac-sha-256, hmacKey) it HMACs field, collection and database names but not operators or parameter names. [source]
- Per-entry metrics include execCount, totalExecMicros, firstResponseExecMicros, docsReturned (sum/max/min/sumOfSquares), and cpuNanos (Linux only, new in 8.2); sumOfSquares exposes variance. Aggregate stage counters are available in the newer output. [source]
- In sharded clusters (new in 8.3) mongod and mongos each record query stats and shards also record stats for queries originating at mongos. Change-stream stats update on cursor creation, getMore and close. [source]
- - To see how often your indexes are used, see [Measure Index Use.](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#std-label-index-measure-index-use) [source]
- The selectivity of regular expressions depends on the expressions themselves. For details, see regular expression and index use. [source]
- The selectivity of [`regular expressions`](https://www.mongodb.com/docs/manual/reference/operator/query/regex.md#mongodb-query-op.-regex) depends on the expressions themselves. For details, see [regular expression and index use.](https://www.mongodb.com/docs/manual/reference/operator/query/regex.md#std-label-regex-index-use) [source]
- Database profiler output, in the command.comment field. [source]
- Returns the details for a single query shape. [source]
- Truncated output, which includes the `queryShapeHash` field: [source]
- Updates the rejection status of a query shape. [source]
- Docs Home / Development / CRUD Operations / Read / Database Profiler [source]
- The database profiler captures data information about read and write operations, cursor operations, and database commands. To configure the database profile and set the thresholds for capturing profile data, see the Database Profiler section. [source]
- The database profiler writes data in the system.profile collection, which is a capped collection. To view the profiler's output, use normal MongoDB queries on the system.profile collection. [source]
- It is no longer possible to perform any operation, including reads, on the system.profile collection from within a transaction. [source]
- For any single operation, the documents created by the database profiler includes a subset of the following fields. The precise selection of fields in these documents depends on the type of operation. [source]
- system.profile.originatingCommand [source]
- system.profile.inUseTrackedMemBytes [source]
- system.profile.peakTrackedMemBytes [source]
- system.profile.hasSortStage [source]
- system.profile.fromMultiPlanner [source]
- system.profile.replanReason [source]
- system.profile.keysInserted [source]
- system.profile.writeConflicts [source]
- system.profile.queryFramework [source]
- The system.profile.locks provides information for various lock types and lock modes held during the operation. [source]
- system.profile.locks.acquireCount [source]
- system.profile.locks.acquireWaitCount [source]
- system.profile.locks.timeAcquiringMicros [source]
- system.profile.locks.deadlockCount [source]
- system.profile.authorization [source]
- system.profile.authorization.startedUserCacheAcquisitionAttempts [source]
- system.profile.authorization.completedUserCacheAcquisitionAttempts [source]
- system.profile.authorization.userCacheWaitTimeMicros [source]
- The system.profile.storage information provides metrics on the storage engine data and wait time for the operation. [source]
- system.profile.storage.data.bytesRead [source]
- system.profile.storage.data.timeReadingMicros [source]
- system.profile.storage.data.bytesWritten [source]
- system.profile.storage.data.timeWritingMicros [source]
- system.profile.storage.timeWaitingMicros.cache [source]
- system.profile.storage.timeWaitingMicros.schemaLock [source]
- system.profile.storage.timeWaitingMicros.handleLock [source]
- system.profile.responseLength [source]
- The system.profile.execStats presents the statistics as a tree; each node provides the statistics for the operation executed during that stage of the query operation. [source]
- system.profile.execStats.stage [source]
- Example system.profile Document [source]
- The system.profile collection includes metrics for the getMore operation. In this example, getMore returns additional documents from the test.report collection. [source]
- Atlas supports Query Shape Insights on only dedicated clusters (M10 and above) running MongoDB version 8.0 and above. [source]
- After you upgrade a cluster from MongoDB 8.x to 9.0, metric totals in Query Shape Insights may appear significantly different than before the upgrade. This difference reflects the change in sampling method, not a change in your cluster's workload. [source]
- 2. Go to Query Shape Insights. [source]
- The Query Shapes tab displays by default. [source]
- Atlas can chart each metric for up to five query shapes at a time. By default, Atlas charts each metric for the five query shapes with the highest Total Execution Time. You can choose to chart different query shapes by selecting or deselecting the checkbox in the row of your desired query shapes. You can manage which query shapes to chart from the table, by selecting or deselecting the checkbox in the row of your desired query shapes. [source]
- [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) users can also manually subscribe to or unsubscribe from Query Shape Reports regardless of whether the project has received a query targeting alert. To learn more, see [Manage Report Subscriptions.](https://www.mongodb.com/docs/atlas/query-shape-insights.md#std-label-query-shape-reports-manage) [source]
- If no qualifying query shapes exist for a given reporting period, Atlas skips that report and resumes with the next scheduled report. [source]
- - A link to the Query Shape Insights page for the cluster. [source]
- - A table of up to five query shapes, ranked by total execution time. Each query shape must have at least 10 executions in the reporting period to appear. [source]
- - A link to each query shape's details on the Query Shape Insights page. [source]
- | Column | Description | | --- | --- | | Collection Name | Name of the collection that the query shape targets. | | Average Execution Time | Average time spent running queries with the given query shape. | | Execution Count | Total number of times that queries with the given query shape ran. | | Docs Examined:Returned Ratio | Ratio of documents examined to documents returned by queries with the given query shape. | [source]
- You can subscribe to or unsubscribe from Query Shape Reports in your project's settings. This setting controls reports for all users in the project. Only users with the [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) role can change the subscription, and only [`Project Owner`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Owner) users receive the reports. [source]
- 1. Toggle the Query Shape Reports setting. [source]
- By default, Query Shape Insights displays metric charts for the top five query shapes with the highest Total Execution Time. You can select up to five query shapes to chart in the Query Shape Insights table. [source]
- - **Query Shape**: In the Search by Query Shape search box, input the query shape or its associated query hash. [source]
- You can sort the Query Shape Insights table by one or more metric columns to help identify which query shapes to chart. [source]
- Click the checkbox in the row of your desired query shape. [source]
- You can select up to five query shapes at a time. [source]
- | Field Name | Description | | --- | --- | | `total` | The total number of queries that performed a collection scan. | | `nonTailable` | The number of queries that performed a collection scan, but didn't use a [tailable cursor.](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) | [source]
- On [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod), if the [database profiler level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) is `2`, full logging is enabled on the profiler and the [`diagnostic log`.](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--logpath) [source]
- At [database profiler level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) `1`, the following settings modify both the profiler and the [`diagnostic log`:](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--logpath) [source]
- If the [database profiler level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) is `0`, the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) is disabled. At level `0` the following settings only modify the diagnostic log: [source]
- - `0` to set the `slowms`, `sampleRate`, and `filter` for the diagnostic log; [source]
- The profiler is off by default. [source]
- Profiling can degrade performance and expose unencrypted query data in the system log. Carefully consider any performance and security implications before configuring and enabling the profiler on a production deployment. [source]
- See [Profiler Overhead](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiling-overhead) for more information on potential performance degradation. [source]
- Atlas Core clusters support all [database profiler levels.](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) [source]
- The [`profile`](https://www.mongodb.com/docs/manual/reference/command/profile.md#mongodb-dbcommand-dbcmd.profile) command obtains a write lock on the affected database while enabling or disabling the profiler. This is typically a short operation. The lock blocks other operations until the [`profile`](https://www.mongodb.com/docs/manual/reference/command/profile.md#mongodb-dbcommand-dbcmd.profile) command has completed. [source]
- [`db.setProfilingLevel()`](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#mongodb-method-db.setProfilingLevel) provides a wrapper around the [`profile`](https://www.mongodb.com/docs/manual/reference/command/profile.md#mongodb-dbcommand-dbcmd.profile) command. [source]
- The [`db.setProfilingLevel()`](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#mongodb-method-db.setProfilingLevel) method has the following form: [source]
- The `filter` and `note` fields only appear in the output if they were present in the previous [level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) setting. [source]
- You can set a `filter` without enabling the database profiler. The following example uses a filter with a [profiling level](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-level) of `0`. [source]
- - the [`drop`](https://www.mongodb.com/docs/manual/reference/command/drop.md#mongodb-dbcommand-dbcmd.drop) command, the [`dropIndexes`](https://www.mongodb.com/docs/manual/reference/command/dropindexes.md#mongodb-dbcommand-dbcmd.dropIndexes) command, the [`validate`](https://www.mongodb.com/docs/manual/reference/command/validate.md#mongodb-dbcommand-dbcmd.validate) command; and [source]
- The fraction of read operations that MongoDB samples for [`$queryStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#mongodb-pipeline-pipe.-queryStats). The value must be between `0.0` and `1.0`. To sample all read operations, set the value to `1.0`. To stop sampling read operations, set the value to `0`. [source]
- The fraction of write operations that MongoDB samples for [`$queryStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#mongodb-pipeline-pipe.-queryStats). The value must be between `0.0` and `1.0`. To sample all write operations, set the value to `1.0`. To stop sampling write operations, set the value to `0`. [source]
- Starting in MongoDB 8.0, the new query shape supports: [source]
- $queryStats query shape statistics. [source]
- operation rejection filters to block find, aggregation, and distinct commands that have a specified query shape. [source]
- queryShapeHash: 'AB8ECADEE8F0EB0F447A30744EB4813AE7E0BFEF523B0870CA10FCBC87F5D8F1' [source]
- In the example in the previous section, the example sorts by the totalNumber field. If you change the query sort from totalNumber to a different field, the query has a different query shape. [source]
- queryShapeHash: 'AC1ECADBE8F1EB0F417A30741AB4813BE7E0BFEF523B0870CA11FCBC87F1A8B2' [source]
- MongoDB derives the queryShapeHash from the query shape itself, not from the deployment that runs the query. In current supported versions, the same query shape is expected to produce the same queryShapeHash: [source]
- Returns the metadata and statistics summary for a given query shape hash. [source]
- The [`$indexStats`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats) stage takes an empty document and has the following syntax: [source]
- - `$indexStats` must be the first stage in an aggregation pipeline. [source]
- Returns a list of query shape statistics summaries for a given cluster. [source]
- Query shape statistics provide performance insights about MongoDB queries, helping users identify problematic query patterns and potential optimizations. [source]
- The [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) method takes the following parameter: [source]
- [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) obtains an exclusive lock on the specified collection for the duration of the operation. All subsequent operations on the collection must wait until [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) releases the lock. [source]
- In [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#std-program-mongosh), this command can also be run through the [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) and [`db.collection.dropIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) helper methods.. [source]
- [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) provides the helper methods [`db.collection.dropIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindex.md#mongodb-method-db.collection.dropIndex) and [`db.collection.dropIndexes()`:](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropindexes.md#mongodb-method-db.collection.dropIndexes) [source]
- ```javascript db.collection.dropIndex("age_1"); ``` [source]
- The total number of [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collections on all databases. [source]
- A document that reports on the number of queries that performed a collection scan. [source]
- The number of queries that performed a collection scan that did not use a [tailable cursor.](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) [source]
- The number of queries that performed a collection scan on a [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection that did not use a [tailable cursor.](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) [source]
- The number of queries that performed a collection scan on a [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection that used a [tailable cursor.](https://www.mongodb.com/docs/manual/core/tailable-cursors.md#std-label-tailable-cursors-landing-page) [source]
- The total number of queries that performed a collection scan on a [`profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection. This includes queries that used both tailable and non-tailable cursors. [source]
- Total number of databases where the [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) is disabled after reaching the lock timeout threshold. [source]
- You can specify the maximum number of lock timeouts per second that disable the profiler by setting the [`internalProfilingMaxAbandonedWritesPerSecondPerDb`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.internalProfilingMaxAbandonedWritesPerSecondPerDb) parameter. [source]
- Number of queries that the `$queryStats` virtual collection has evicted due to space contraints. [source]
- Current estimated size of objects in the `$queryStats` virtual collection. [source]
- Forbids operations that require a collection scan. See [`notablescan`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.notablescan) for additional information. [source]
- Configures the [database profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md) level. The following profiler levels are available: [source]
- The profiler is off and does not collect any data. This is the default profiler level. [source]
- The profiler collects data for operations that exceed the `slowms` threshold or match a specified [filter.](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter) [source]
- - The profiler only captures operations that match the [filter.](https://www.mongodb.com/docs/manual/reference/method/db.setprofilinglevel.md#std-label-set-profiling-level-options-filter) [source]
- The profiler collects data for all operations. [source]
- For `mongod` instances, [`--slowms`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--slowms) affects the diagnostic log and, if enabled, the profiler. [source]
- For `mongod` instances, [`--slowOpSampleRate`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#std-option-mongod.--slowOpSampleRate) affects the diagnostic log and, if enabled, the profiler. [source]
- - Do not depend on the profiling level. [source]
- Monitor Query Shape Statistics with Query Shape Insights [source]
- How Atlas Collects Query Shape Statistics [source]
- Total time in microseconds spent running queries with the given query shape. If the query resulted in getMore commands, this metric includes the time spent processing the getMore requests. This metric does not include time spent waiting for the client. [source]
- Average time in microseconds spent running queries with the given query shape. If the query resulted in getMore commands, this metric includes the time spent processing the getMore requests. This metric does not include time spent waiting for the client. [source]
- Total number of times that queries with the given query shape have been executed. [source]
- Total number of documents examined by queries with the given query shape. [source]
- Total number of documents returned by queries with the given query shape. [source]
- Ratio of documents examined to documents returned by queries with the given query shape. [source]
- Total number of documents matched by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Total number of documents modified by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Total number of documents upserted by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Total number of documents inserted by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Total number of documents deleted by queries with the given query shape. Available only for write commands on clusters running MongoDB 9.0 or later. [source]
- Execution runtime in microseconds for the most recent query with the given query shape. [source]
- Project Owner users can also manually subscribe to or unsubscribe from Query Shape Reports regardless of whether the project has received a query targeting alert. To learn more, see Manage Report Subscriptions. [source]
- Name of the collection that the query shape targets. [source]
- Average time spent running queries with the given query shape. [source]
- Total number of times that queries with the given query shape ran. [source]
- - [Query Shape Reports](https://www.mongodb.com/docs/atlas/query-shape-insights.md#std-label-query-shape-reports), which send a summary of inefficient query shapes to Project Owners by email. [source]
- - The [Query Profiler](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-query-profiler), which describes specific inefficient queries executed on the cluster. [source]
- 2. Go to the Query Profiler tab. [source]
- Click the Query Profiler tab. [source]
- $queryStats collects and reports metrics for aggregate(), find(), distinct(), count(), update(), insert(), deleteOne(), and deleteMany() queries. $queryStats does not collect information for queries that use Queryable Encryption. [source]
- The $queryStats stage is enabled on deployments hosted on MongoDB Atlas with a cluster tier of at least M10. [source]
- $queryStats must be the first stage in the pipeline. [source]
- Specifies additional transformation options for the $queryStats output. [source]
- The following sections describe behavioral details of the $queryStats stage. [source]
- How $queryStats Groups Returned Documents [source]
- $queryStats preserves literal values for options like readConcern and readPreference. [source]
- For the complete list of options included in a query stats entry, see find Command Query Shape. [source]
- How $queryStats Transforms Data Using transformIdentifiers [source]
- MongoDB records $queryStats operations in the deployment logs. By default, MongoDB only logs the invocation of $queryStats operations, not the operation's output. For $queryStats operations that include the transformIdentifiers option, you can specify whether the transformed output is included in the log entry. [source]
- Each unique combination of attributes creates a separate entry in the $queryStats virtual collection. [source]
- A hashed representation of the values in the key. Each unique keyHash value corresponds to a unique entry in the $queryStats memory store. [source]
- Collection scan stages, counted separately based on whether the stage applies a filter. [source]
- The fields in key.queryShape vary based on the command that resulted in the query stats entry. $queryStats creates query stats entries for aggregate, find, distinct, count, update, insert, and delete commands. [source]
- Each query shape property corresponds to a query option. For example, key.queryShape.sort corresponds to the sort() specification for the query shape. [source]
- The following table describes the query shape properties for find commands. [source]
- key.queryShape.projection [source]
- key.queryShape.singleBatch [source]
- key.queryShape.showRecordId [source]
- key.queryShape.oplogReplay [source]
- key.queryShape.allowDiskUse [source]
- The following table describes the query shape properties for aggregate commands. [source]
- key.queryShape.allowPartialResults [source]
- The following table describes the query shape properties for distinct commands. [source]
- The following table describes the query shape properties for count commands. [source]
- The following table describes the query shape properties for update commands. $queryStats tracks query shape statistics for each update statement in the updates array, not for the top-level update command as a whole. [source]
- key.queryShape.arrayFilters [source]
- $queryStats does not collect query shape statistics for update operations on time series collections. [source]
- The following table describes the query shape properties for insert commands. $queryStats tracks query shape statistics once for the entire insert command, not for each document in the documents array. MongoDB always normalizes documents to a fixed placeholder value, regardless of the number or contents of the inserted documents. [source]
- $queryStats does not collect query shape statistics for insert operations on time series collections. [source]
- The following table describes the query shape properties for delete commands. $queryStats tracks query shape statistics for each delete statement in the deletes array, not for the top-level delete command as a whole. [source]
- $queryStats does not collect query shape statistics for delete operations on time series collections. [source]
- The example $queryStats output in the following sections may vary based on the execution of other commands. [source]
- const pipeline = [{ $queryStats: {} }]; [source]
- MongoDB Atlas periodically uses $queryStats to collect anonymized data about your queries, which helps improve MongoDB products. Your data may also be used to make feature suggestions based on usage. MongoDB retains the data it collects with $queryStats for four years. [source]
- On a system with profiling enabled, you can then query the `system.profile` collection to see all recent similar aggregations, as shown below: [source]
- | Field | Necessity | Type | Description | | --- | --- | --- | --- | | `transformIdentifiers` | Optional | Document | Specifies additional transformation options for the `$queryStats` output. | | `transformIdentifiers``.algorithm` | Required if specifying the `transformIdentifiers` object | String | The type of hash transformation applied to namespace information and field names in output. The only currently supported `algorithm` value is `hmac-sha-256`. | | `transformIdentifiers``.hmacKey` | Required if specifying the `transformIdentifiers` object | binData | The private key input in the HMAC [source]
- - To run `$queryStats` without the `transformIdentifiers` option, the user must have the [`queryStatsRead`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-queryStatsRead) privilege action. [source]
- - To run `$queryStats` with the `transformIdentifiers` option, the user must have the both the [`queryStatsRead`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-queryStatsRead) and [`queryStatsReadTransformed`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-queryStatsReadTransformed) privilege actions. [source]
- For the complete list of options included in a query stats entry, see [find Command Query Shape.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-find-query-shape) [source]
- `$queryStats` does not collect query shape statistics for `update` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) [source]
- `$queryStats` does not collect query shape statistics for `insert` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) [source]
- `$queryStats` does not collect query shape statistics for `delete` operations on [time series collections.](https://www.mongodb.com/docs/manual/core/timeseries-collections.md#std-label-manual-timeseries-collection) [source]
- The database profiler captures data information about read and write operations, cursor operations, and database commands. To configure the database profile and set the thresholds for capturing profile data, see the [Database Profiler](https://www.mongodb.com/docs/manual/tutorial/manage-the-database-profiler.md#std-label-database-profiler) section. [source]
- It is no longer possible to perform any operation, including reads, on the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection from within a [transaction.](https://www.mongodb.com/docs/manual/core/transactions.md#std-label-transactions) [source]
- The [`system.profile.locks`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks) provides information for various [lock types and lock modes](https://www.mongodb.com/docs/manual/faq/concurrency.md#std-label-faq-concurrency-locking) held during the operation. [source]
- [`timeAcquiringMicros`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks.timeAcquiringMicros) divided by [`acquireWaitCount`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.locks.acquireWaitCount) gives an approximate average wait time for the particular lock mode. [source]
- The [`system.profile.storage`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.storage) information provides metrics on the storage engine data and wait time for the operation. [source]
- The [`system.profile.execStats`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.execStats) presents the statistics as a tree; each node provides the statistics for the operation executed during that stage of the query operation. [source]
- The following fields list for [`execStats`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.execStats) is not meant to be exhaustive as the returned fields vary per stage. [source]
- The following examples present sample documents found in the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection for operations on a standalone: [source]
- The following document in the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system-collections.md#mongodb-data--database-.system.profile) collection shows metrics for a sample query operation on the `test.report` collection: [source]
- - [atlas api queryShapeInsights getClusterQueryShape](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryshapeinsights-getclusterqueryshape.md#std-label-atlas-api-queryShapeInsights-getClusterQueryShape) - Returns the details for a single query shape. [source]
- - [atlas api queryShapeInsights getQueryShapeDetails](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryshapeinsights-getqueryshapedetails.md#std-label-atlas-api-queryShapeInsights-getQueryShapeDetails) - Returns the metadata and statistics summary for a given query shape hash. [source]
- - [atlas api queryShapeInsights listClusterQueryShapes](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryshapeinsights-listclusterqueryshapes.md#std-label-atlas-api-queryShapeInsights-listClusterQueryShapes) - Returns a list of query shapes for one cluster. [source]
- - [atlas api queryShapeInsights listQueryShapeSummaries](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryshapeinsights-listqueryshapesummaries.md#std-label-atlas-api-queryShapeInsights-listQueryShapeSummaries) - Returns a list of query shape statistics summaries for a given cluster. [source]
- - [atlas api queryShapeInsights updateClusterQueryShape](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-queryshapeinsights-updateclusterqueryshape.md#std-label-atlas-api-queryShapeInsights-updateClusterQueryShape) - Updates the rejection status of a query shape. [source]
- A tailable cursor performs a collection scan over a [capped collection](https://www.mongodb.com/docs/manual/core/capped-collections.md#std-label-manual-capped-collection). It remains open even after reaching the end of the collection. Applications can continue to iterate the tailable cursor as new data is inserted into the collection. [source]
- Including `$queryStats` output in the logs provides more information on specific `$queryStats` operations, but can negatively impact cluster performance as log updates take more time and resources. [source]
- For an example of transformed `$queryStats` output, see [Transformed Example.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-example-transformed) [source]
- The following entries show `$queryStats` output for `find`, `aggregate`, `update`, `insert`, and `delete` commands. [source]
- Both the Atlas Query Profiler and the database profiler can affect server performance, use up disk space, and expose query metadata around encrypted fields. Consider the performance and security implications before enabling them. [source]
- Are affected by slowOpSampleRate. [source]
- The original query shape of the mongos operation may differ after the mongos sends the operation to the mongod . [source]
- Starting in MongoDB 6.3, a message is added to the log if the time to send an operation response exceeds the slowms threshold option. [source]
- A session workflow message is added to the log if sendResponseMillis exceeds the slowms threshold option. [source]
- A hexadecimal string that represents the hash of the [query shape](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-query-shape). For more information, see [Query Shapes.](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) [source]
- Number of queries executed per hour which match the query shape. [source]
- Average execution time in milliseconds for queries which match the query shape. [source]
- A session workflow message is added to the log if `sendResponseMillis` exceeds the [slowms threshold option.](https://www.mongodb.com/docs/manual/reference/command/profile.md#std-label-slowms-threshold-option) [source]
- - [operation rejection filters](https://www.mongodb.com/docs/manual/tutorial/operation-rejection-filters.md#std-label-operation-rejection-filters) to block `find`, `aggregation`, and `distinct` commands that have a specified query shape. [source]
- For more information about query shapes, see [Query Shapes.](https://www.mongodb.com/docs/manual/core/query-shapes.md#std-label-query-shapes) [source]
- The Atlas Query Profiler supports binning operations of the same type running on the same collection around the same timestamp to support additional datapoints. [source]
- **Important: Please read the following considerations before you enable the Query Profiler.** [source]
- 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. [source]
- Atlas displays no more than 100,000 data points in the Query Profiler charts. [source]
- The Query Profiler does not include bulk operations in its query sampling and analysis. Bulk write operations are excluded from the profiled queries displayed in the Query Profiler. Excluded operations include [`bulkWrite()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.bulkWrite.md#mongodb-method-db.collection.bulkWrite), `updateMany` with multiple `stmtIds`, and similar multi-document operations. [source]
- Atlas enables the Query Profiler by default. [source]
- 2. Disable the Query Profiler. [source]
- In the Database Monitoring Tools section, toggle Performance Advisor and Profiler to Off. [source]
- The Query Profiler displays all your data from the log on the [primary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-primary) and [secondary](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-secondary) nodes by default. [source]
- 3. Customize the Query Profiler. [source]
- 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. [source]
- Click the All operation types dropdown to change which operations you want to profile. The Query Profiler displays all operation types by default. [source]
- A hexadecimal string that represents the hash of the query shape. For more information, see Query Shapes. [source]
- 2. Toggle the button next to Performance Advisor and Profiler. [source]
- Query Shape Reports, which send a summary of inefficient query shapes to Project Owners by email. [source]
- The Query Profiler, which describes specific inefficient queries executed on the cluster. [source]
- Returns a list of query shapes for one cluster. [source]
- Query shapes may be filtered by their status; at present, this endpoint supports only the REJECTED status. [source]
- The Query Profiler displays all your data from the log on the primary and secondary nodes by default. [source]
- A query shape groups similar queries by filters, sorts, projections, aggregation pipeline stages and namespace, ignoring literal values; queries with the same specification share one shape. [source]
- Datadog's Atlas integration streams query shape metrics under the mongodb.atlas.querystats prefix with samplingstrategy (sampled | rate_limited) and samplingrate tags; M10+ only. [source]
- Depending on the distribution of data in the cluster and the selectivity of the query, mongos may still perform a broadcast operation to fulfill these queries. [source]
- Depending on the distribution of data in the cluster and the selectivity of the query, [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos) may still perform a [broadcast operation](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#std-label-sharding-mongos-broadcast) to fulfill these queries. [source]
Related concepts
- database profiler — is a part of MongoDB query shapes, $queryStats, profiler and index usage
- query shape — is a part of MongoDB query shapes, $queryStats, profiler and index usage
- index — is a hypernym of MongoDB query shapes, $queryStats, profiler and index usage
- $indexStats — is a part of MongoDB query shapes, $queryStats, profiler and index usage
- index effectiveness — is a measure of MongoDB query shapes, $queryStats, profiler and index usage
- query optimization — is a hypernym of MongoDB query shapes, $queryStats, profiler and index usage
- $currentOp — is a related of MongoDB query shapes, $queryStats, profiler and index usage
Children
- No children recorded.