<!-- llms-explorer concept facts · https://llms-explorer.com/tree/mongodb-explain-output-and-stages/ · pack 2026-10-19 · ~45409 tokens -->

# MongoDB explain output and plan stages

> Explain plan results for queries are subject to change between MongoDB versions. (from www.mongodb.com)

Parent: [Global AI Hub Research Corpus](https://llms-explorer.com/tree/global-ai-hub-research-corpus/) · 9 facets · 571 facts · page: https://llms-explorer.com/tree/mongodb-explain-output-and-stages/

## Definitions

- Stage meanings per MongoDB: COLLSCAN is a collection scan, IXSCAN an index scan, FETCH reads full documents, PROJECTION filters returned fields in memory, and SORT means documents were sorted in memory (or a covered index was used). A filter or sort that shows COLLSCAN would benefit from an index; docsExamined appears on COLLSCAN and FETCH stages and keysExamined on IXSCAN. — [source](https://www.mongodb.com/docs/manual/tutorial/explain-slow-queries/)
- Where `<string>>` is the field that is indexed and `<value>` is either the direction of the index, or the special index type such as `text` or `2dsphere`. See [index types](https://www.mongodb.com/docs/manual/core/indexes/index-types.md#std-label-index-types) for the full list of index types. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.stats.md#index-filter-behavior)
- - If the `$facet` stage is the first stage in a pipeline, the stage will perform a `COLLSCAN`. The `$facet` stage does not make use of indexes if it is the first stage in the pipeline. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet.md#index-use)
- For example, in the following document, `metadata` is a good choice of `metaField` since it makes it easy to query data from a given weather sensor. Using these fields, MongoDB buckets readings from a single sensor together. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-the-metafield-affects-bucketing)
- The default name for an index is the concatenation of the indexed keys and each key's direction in the index (`1` or `-1`) using underscores as a separator. For example, an index created on `{ item : 1, quantity: -1 }` has the name `item_1_quantity_-1`. — [source](https://www.mongodb.com/docs/manual/indexes.md#index-names)

## Structure and components

- | Field | Description | Applicable Stages | | --- | --- | --- | | `docsExamined` | Specifies the number of documents scanned during the query execution stage. | `COLLSCAN`, `FETCH` | | `keysExamined` | For query execution stages that scan an index `keysExamined` is the total number of in-bounds and out-of-bounds keys that are examined in the process of the index scan. If the index scan consists of a single contiguous range of keys, only in-bounds keys need to be examined. If the index bounds consists of several key ranges, the index scan execution process may examine out-of-bounds keys in orde — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Starting in MongoDB 5.3, if the query planner selects a [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) for a [clustered collection](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) and the query contains bounds that define the portion of the index to search, the explain result includes a `CLUSTERED_IXSCAN` stage. The stage includes information about the clustered index key and index bounds. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#collection-scan)
- If the query planner selects a [clustered index](https://www.mongodb.com/docs/manual/reference/method/db.createcollection.md#std-label-db.createCollection.clusteredIndex) for a [clustered collection](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) and the query *does not* contain bounds, the query performs an unbounded collection scan and the explain result includes a `COLLSCAN` stage. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#collection-scan)
- If the query planner selects a clustered index for a clustered collection and the query does not contain bounds, the query performs an unbounded collection scan and the explain result includes a COLLSCAN stage. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Each stage consists of information specific to the stage. For example, an `IXSCAN` stage includes the index bounds along with other data specific to the index scan. If a stage has a child stage or multiple child stages, the stage will have an `inputStage` or `inputStages`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Each stage consists of information specific to the stage. For example, an `IXSCAN` stage includes the index bounds along with other data specific to the index scan. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Contains *partial* execution information captured during the [plan selection phase](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) for both the winning and rejected plans. The field is present only if `explain` runs in `allPlansExecution` verbosity mode. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- The `explain` results present the query plans as a tree of stages. The output structure can differ based on which query engine the operation uses. Operations can use the classic query engine or the [slot-based execution query engine.](https://www.mongodb.com/docs/manual/reference/sbe.md#std-label-sbe-landing) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#explain-output-structure)
- If query settings are set, `querySettings` contains details about the query settings that are applied to the query shape. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Contains information on the selection of the query plan by the [query optimizer.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- The explain results present the query plans as a tree of stages. The output structure can differ based on which query engine the operation uses. Operations can use the classic query engine or the slot-based execution query engine. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Contains statistics that describe the completed query execution for the winning plan. For write operations, completed query execution refers to the modifications that *would* be performed, but does *not* apply the modifications to the database. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Total time in milliseconds required for query plan selection and query execution. It includes the time it takes to run the trial phase part of the plan selection process, but does not include the network time to transmit the data back to the client. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- If you run [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) on a `$setWindowsFields` operation, the output contains a `peakTrackedMemBytes` field that contains the maximum number of bytes of tracked memory in use. For more information, see [`explain.executionStats.peakTrackedMemBytes`.](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.peakTrackedMemBytes) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields.md#explain-output)
- [`explain.executionStats.totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) refers to the total number of documents examined and *not* to the number of documents returned. For example, a stage can examine a document in order to apply a filter. If the document is filtered out, then it has been examined but will not be returned as part of the query result set. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Contains resource consumption statistics, as long as they are not zero. The field is present only if `explain` runs in `executionStats` verbosity mode or higher and if `profileOperationResourceConsumptionMetrics` is enabled. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Each `inputStage` can have another `inputStage` as a field. See [Explain Output Structure.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-structure) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Each inputStage can have another inputStage as a field. See Explain Output Structure. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- For query execution stages that scan an index keysExamined is the total number of in-bounds and out-of-bounds keys that are examined in the process of the index scan. If the index scan consists of a single contiguous range of keys, only in-bounds keys need to be examined. If the index bounds consists of several key ranges, the index scan execution process may examine out-of-bounds keys in order to skip from the end of one range to the beginning of the next. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Contains partial execution information captured during the plan selection phase for both the winning and rejected plans. The field is present only if explain runs in allPlansExecution verbosity mode. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Specifies the number of "work units" performed by the query execution stage. Query execution divides its work into small units. A "work unit" might consist of examining a single index key, fetching a single document from the collection, applying a projection to a single document, or doing a piece of internal bookkeeping. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- For example, consider a query for `"item": "saccharomyces cerevisiae"` and `"stock": 60`. If the collection contains 10000 documents matching `"item": "saccharomyces cerevisiae"` and only 100 of those documents match `"stock": 60`, the query examines 10000 keys. In the `IXSCAN` stage, the query filters those keys by the `stock` field and only returns 100 results to the next stage. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#index-prefixes)
- For example, with a granularity of `seconds`, MongoDB buckets documents within the same hour. If a bucket contains a document with a `metaField` value of `sensorA` and a `timeField` value of `2024-08-01T18:23:21Z`, an incoming document with a `metaField` of `sensorB` goes into a separate bucket regardless of time. An incoming document from `sensorA` goes into the same bucket only if its `timeField` is between `2024-08-01T18:00:00Z` and `2024-08-01T18:59:59Z`. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-bucketing-works)
- - The [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) command [results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) contain a new `BATCHED_DELETE` stage for batched document deletions. — [source](https://www.mongodb.com/docs/manual/core/index-ttl.md#delete-operations)
- The bounds of an index scan define the parts of an index to search during a query. The computation of multikey index bounds follows special rules. For details, see Multikey Index Bounds. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/)
- The bounds of an index scan define the parts of an index to search during a query. The computation of multikey index bounds follows special rules. For details, see [Multikey Index Bounds.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-indexes-multikey-bounds) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey.md#index-bounds)
- The explain command results contain a new BATCHED_DELETE stage for batched document deletions. — [source](https://www.mongodb.com/docs/manual/core/index-ttl/)
- For more information about the differences in explain results between query engines, see [Explain Output Structure.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-structure) — [source](https://www.mongodb.com/docs/manual/reference/sbe.md#check-query-explain-results)
- An array that contains statistics for the operations that are the input stages of the current stage. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- Object that contains two fields: true and false. Each field counts the number of matching queries where the value of usedDisk is true or false, respectively. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- | Field | Necessity | Description | | --- | --- | --- | | [field](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#std-label-densify-field) | Required | The field to densify. The values of the specified `field` must either be all numeric values or all dates. Documents that do not contain the specified `field` continue through the pipeline unmodified. To specify a `<field>` in an embedded document or in an array, use [dot notation.](https://www.mongodb.com/docs/manual/core/document.md#std-label-document-dot-notation) For restrictions, see [`field` Restrictions.](htt — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#syntax)
- In prior versions, [`$densify`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#mongodb-pipeline-pipe.-densify) treats bounds with an equal lower and upper bound as a closed interval and generates a document with the bound value as a field value if the collection does not already contain a document with the bound value. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#range-bounds-behavior)

## How it works

- The Atlas docs' worked example: a log line with planSummary COLLSCAN, keysExamined 0, docsExamined 10000, nreturned 4 gives a ratio of 2500. Atlas names a missing index or an index that only partially supports the query as the typical cause, and recommends Performance Advisor, Query Shape Reports and Query Targeting metrics for follow-up. — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting/)
- The time reported by `explain.executionStats.executionTimeMillis` is not necessarily representative of actual query time. During steady state operations (when the query plan is cached), or when using [`cursor.hint()`](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md#mongodb-method-cursor.hint) with `cursor.explain()`, MongoDB bypasses the plan selection process, resulting in a faster actual time, leading to a lower `explain.executionStats.executionTimeMillis` value. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- | Counter | Description | | --- | --- | | `collscan``clusteredCollscan` | Collection scans, counted separately based on whether the scan uses the [clustered index.](https://www.mongodb.com/docs/manual/core/clustered-collections.md#std-label-clustered-collections) | | `coveredIxscan` | Index scans that don't fetch documents. | | `ixscanFetch` | Index scans that fetch documents. | | `countScan` | Scans that count index keys without returning documents. | | `distinctScan``distinctScanFetch` | Scans that skip duplicate index keys, counted separately based on whether the scan fetches documents. | | — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#access-path-counters)
- When totalKeysExamined is far lower than totalDocsExamined, the docs say to inspect each stage in executionStats.executionStages and compare keysExamined with docsExamined per stage to find which stage failed to use the index. A totalKeysExamined of 0 with large totalDocsExamined indicates a pure collection scan. — [source](https://www.mongodb.com/docs/manual/tutorial/explain-slow-queries/)
- keysExamined counts both in-bounds and out-of-bounds keys. When index bounds have several key ranges, the scan examines out-of-bounds keys to skip from one range to the next, so keysExamined can exceed the matching key count without the index being bad. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- As with any hash function, two different plan cache query shapes may result in the same hash value. However, the occurrence of hash collisions between different plan cache query shapes is unlikely. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- Because the query shapes are the same, the explain output has the same queryShapeHash for each of the examples, and the same planCacheShapeHash for each. For example: — [source](https://www.mongodb.com/docs/manual/core/query-shapes/)
- Because the query shape is different from the shape in the previous section, the explain output has a different queryShapeHash from the previous example, and a different planCacheShapeHash. For example: — [source](https://www.mongodb.com/docs/manual/core/query-shapes/)
- Float that represents the estimated number of index keys that the query planner predicts the plan to process. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A cached plan is replanned when its re-run trial does more than internalQueryCacheEvictionRatio (reported default 10) times the work of the original trial. In SBE, SERVER-85238 uses this ratio as a multiplier on the winner's totalKeysExamined + totalDocsExamined as the replanning read budget. The default of 10 comes only from a third-party slide deck, not official docs. — [source](https://www.slideshare.net/slideshow/query-planner-88498371/88498371)
- When you create an index, you can give the index a custom name. Giving your index a name helps distinguish different indexes on your collection. For example, you can more easily identify the indexes used by a query in the query plan's [explain results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) if your indexes have distinct names. — [source](https://www.mongodb.com/docs/manual/core/indexes/create-index/specify-index-name.md)
- Starting in MongoDB 8.3, multi-planning with a CBR backup is the default plan selection mechanism for eligible queries. For a short trial period, the multi-planner attempts to find a plan capable of returning a result set within this short timeframe. If the attempt is unsuccessful, MongoDB applies a set of rules to determine whether the multi-planner should continue or if CBR should evaluate each node in the plan to determine the optimal plan. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#queryplanner)
- When you sort based on an array field that is indexed with a multikey index, the query plan includes an in-memory sort stage unless both of the following are true: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/)
- `notablescan` does not allow unbounded queries that use a clustered index because the queries require a full collection scan. For more information, see [Collection Scans.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-collection-scan) — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- - [`executionStats.totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) displays `3809` to indicate that MongoDB scanned 3,809 index entries. The number of keys examined match the number of documents returned, meaning that the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) only had to examine index keys to return the results. The [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) did not have to scan all — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- When the slot-based query execution engine is used for [`$group`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#mongodb-pipeline-pipe.-group), the [explain results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) include `queryPlanner.winningPlan.queryPlan.stage: "GROUP"`. — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#group-optimization)
- When the slot-based query execution engine is used for [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup), the [explain results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) include `queryPlanner.winningPlan.queryPlan.stage: "EQ_LOOKUP"`. `EQ_LOOKUP` means "equality lookup". — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#lookup-optimization)
- - `heuristics`: Uses a set of rules to determine selectivity. Only used when sampling fails. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - If the `$facet` stage comes later in the pipeline and earlier stages have used indexes, `$facet` will not trigger a `COLLSCAN` during execution. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet.md#index-use)
- For example, [`$match`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/match.md#mongodb-pipeline-pipe.-match) or [`$sort`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort.md#mongodb-pipeline-pipe.-sort) stages that come before a `$facet` stage can make use of indexes and the `$facet` will not trigger a `COLLSCAN`. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet.md#index-use)
- With Queryable Encryption, MongoDB tracks the occurrences of each field/value pair in an encrypted collection using an internal counter. The [contention factor](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-contention-factor) partitions this counter, similar to an array. This minimizes issues with incrementing the counter when using `insert`, `update`, or `findAndModify` to add or modify an encrypted field with the same field/value pair in close succession. `contention = 0` creates an array with one element at index 0. `contention = 4` creates an array with 5 elements at i — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- Last point queries are most performant when they use the [DISTINCT\_SCAN optimization](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results). This optimization is only available when an index on `timeField` is descending. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- Bounds intersection refers to the point where multiple bounds overlap. For example, given the bounds `[ [ 3, Infinity ] ]` and `[ [ -Infinity, 6 ] ]`, the intersection of the bounds results in `[ [ 3, 6 ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#bounds-intersection-for-a-multikey-index)
- Because the query uses `$elemMatch` to join these predicates, MongoDB intersects the bounds to: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- Because the preceding query does not use `$elemMatch`, MongoDB does not intersect the bounds. Instead, MongoDB uses either of the following bounds: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#query-without-elemmatch)
- When an index covers a query, the explain result has an `IXSCAN` stage that is **not** a descendant of a `FETCH` stage. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#covered-queries)
- Limits how many digits after the decimal point are taken into account when querying a `double` or `decimal` field. Additional digits are dropped, not rounded. For example, a `precision` of 1 treats `10.18` as `10.1` for queries. The encrypted value is still stored as `10.18`. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- When unset, `contention` defaults to `8`, which provides high performance for most workloads. Higher contention improves the performance of insert and update operations on low cardinality fields, but decreases find performance. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- Because `metaField` values must match exactly to group documents, the number of buckets in a time series collection depends on the number of unique `metaField` values. Collections with fine-grained or changing `metaField` values generate many sparsely packed, short-lived buckets. This leads to decreased storage and query efficiency. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-the-metafield-affects-bucketing)
- 4. Queryable Encryption implements a fast, searchable scheme that allows the server to process queries on fully encrypted data, without knowing anything about the data. The data and the query itself remain encrypted at all times on the server. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#how-queryable-encryption-works)
- Setting [`cursorTimeoutMillis`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.cursorTimeoutMillis) to less than or equal to `0` results in all cursors being immediately eligible for timeout. Generally, the timeout value should be greater than the average amount of time for a query to return results. Use tools like the [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) cursor modifier to analyze the average query time and select an appropriate timeout period. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- **Index bounds** define the range of index values that MongoDB searches when using an index to fulfill a query. When you specify multiple query predicates on an indexed field, MongoDB attempts to combine the bounds for those predicates to produce an index scan with smaller bounds. Smaller index bounds result in faster queries and reduced resource use. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md)
- Compound bounds combine bounds for multiple keys of a [compound index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound). Using bounds from multiple keys reduces the time it takes to process a query because MongoDB does not need to compute results for each bound individually. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#compound-bounds-for-a-multikey-index)
- The following example shows how MongoDB uses compound bounds when an index includes a non-array field and multiple array fields. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- The fields `"ratings.scores.q1"` and `"ratings.scores.q2"` share the field path `"ratings.scores"`. In order to compound index bounds, a query must use `$elemMatch` on the common field path. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-elemmatch-on-diverging-field-paths)
- Specifies the *inclusive* lower bound for a specific index in order to constrain the results of [`find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#mongodb-method-db.collection.find). [`min()`](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#mongodb-method-cursor.min) provides a way to specify lower bounds on compound key indexes. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#definition)
- The Explain Plan doesn't show aggregation pipeline stages such as [`$merge`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge.md#mongodb-pipeline-pipe.-merge) and [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) because Atlas ignores all out stages from the aggregation before running the explain plan. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/query-plan.md#about-this-task)
- Index scans, counted separately by the index bounds that the scan uses. MongoDB increments boundsMixture when the scan uses more than one type of bound. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- `$in` compares each parameter to each document in the collection, which can cause performance issues. To improve performance, create an index on the `field` you want to query. An index allows MongoDB to create bounds for each `$in` element and search more efficiently. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/in.md#syntax)
- For example, `$group` operations of the following form can result in a `DISTINCT_SCAN`: — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#retrieve-distinct-values)
- Number of post-recovery waits that completed when the cluster's config time advanced since the server started. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#shard)
- usedDisk is true when the query writes data to temporary files due to memory restrictions. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- MongoDB follows prevaling database usage and works with time in UTC. The `dateSubtract` expression always takes a `startDate` in UTC and returns a result in UTC. If the `timezone` is specified, the calculation will be done using the specified `timezone`. The timezone is especially important when a calculation involves Daylight Savings Time (DST). — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract.md#time-measurement)
- - When you specify Polygon `coordinates`, the first and last coordinates in the array must be the same. This closes the bounds of the polygon. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2dsphere/query/geojson-bound-by-polygon.md#about-this-task)
- The sort direction is descending because the `sortBy` value is "-1". — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray.md#sort-on-a-subfield)

## How-to and procedures

- To see whether MongoDB will apply an index filter for a plan cache query shape, check the [`indexFilterSet`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.indexFilterSet) field of either the [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) or the [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method. — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md#set-filter-on-plan-cache-query-shape-consisting-of-predicate-only)
- Use the [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) or the [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method in [executionStats](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-executionStats) mode to return statistics about the query process, including the index used, the number of documents scanned, and the time the query takes to process in milliseconds. — [source](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#return-query-plan-with-explain)
- Run [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) or the [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method in [allPlansExecution](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-allPlansExecution) mode to view partial execution statistics collected during plan selection. — [source](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#return-query-plan-with-explain)
- To compare candidate indexes, run the same query with hint() and explain('executionStats') and compare totalKeysExamined. In the MongoDB docs example, {year:1, rated:1} scanned 246 keys for 235 results while {rated:1, year:1} scanned 235, so the second is more efficient (equality field before range field). — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- To view the query plan selected, chain the [`cursor.explain("executionStats")`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) cursor method to the end of the **find** command: — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- To view the MongoDB 8.0 queryShapeHash and planCacheShapeHash hexadecimal strings, you can use the explain command. — [source](https://www.mongodb.com/docs/manual/core/query-shapes/)
- To hide a text index, you must specify the index by `name` and not by `keyPattern`. — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#hide-an-index-from-the-query-planner)
- To view the execution statistics for a specific index, append to the [`db.collection.find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#mongodb-method-db.collection.find) the [`hint()`](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md#mongodb-method-cursor.hint) method followed by [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain), e.g.: — [source](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#control-index-use-with-hint)
- To manually compare the performance of a query using more than one index, you can use the [`hint()`](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md#mongodb-method-cursor.hint) method in conjunction with the [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- To manually compare the performance of a query using more than one index, you can use the hint() method in conjunction with the explain() method. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- To determine whether a pipeline uses indexes, review the query plan and look for `IXSCAN` or `DISTINCT_SCAN` plans. — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#indexes)
- To add query settings and explore examples, which include `explain()` output with `querySettings`, see [`setQuerySettings`.](https://www.mongodb.com/docs/manual/reference/command/setquerysettings.md#mongodb-dbcommand-dbcmd.setQuerySettings) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- To view the query plan information for a given query, you can use [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) or the [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) . — [source](https://www.mongodb.com/docs/manual/core/query-plans.md#query-plan-and-cache-information)
- To view the query plan statistics, use the [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method: — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- To analyze query performance, see [Interpret Explain Plan Results.](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md) — [source](https://www.mongodb.com/docs/manual/core/query-optimization.md#create-indexes-to-support-queries)
- To see whether your operation results in a `DISTINCT_SCAN`, check your operation's [explain results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/group.md#retrieve-distinct-values)
- To see how many documents were scanned to return the query, view the query's [`executionStats`:](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/limit-number-of-items-scanned-for-text-search.md#view-number-of-documents-examined)
- To add query settings and explore examples, which include explain() output with querySettings, see setQuerySettings. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- To analyze query performance, see Interpret Explain Plan Results. — [source](https://www.mongodb.com/docs/manual/core/query-optimization/)
- To confirm whether a query used an index, run the query with the [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) option. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex.md#create-indexes-with-collation)
- Create a [compound multikey index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound) on the `item` and `ratings` fields: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- To compound the bounds for `"ratings.score"` with the bounds for `"ratings.by"`, the query must use `$elemMatch`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- Create a compound index on the `ratings.score` and the `ratings.by` fields: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example)
- Create a compound index on the `ratings.scores.q1` and the `ratings.scores.q2` fields: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-elemmatch-on-diverging-field-paths)
- To compound the bounds, the query must use `$elemMatch` on the common path `"ratings.scores"`: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-elemmatch-on-diverging-field-paths)
- To confirm that the sort operation used the Secondary Index, run the operation again with the `.explain( "executionStats" )` option: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#use-secondary-indexes-to-improve-sort-performance)
- To confirm that the last point query used the secondary index, run the operation again using `.explain( "executionStats" )`: — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- To view a step-by-step guide demonstrating how to use a remote KMS with Queryable Encryption, see [Queryable Encryption Tutorials.](https://www.mongodb.com/docs/manual/core/queryable-encryption/tutorials.md#std-label-qe-tutorial-automatic-encryption) — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#how-queryable-encryption-works)
- To view a list of all supported KMS providers, see [KMS Providers.](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/kms-providers.md#std-label-qe-fundamentals-kms-providers) — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#how-queryable-encryption-works)
- To learn more about why you should use a remote KMS, see [Reasons to Use a Remote Key Management System.](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/kms-providers.md#std-label-qe-reasons-to-use-remote-kms) — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#how-queryable-encryption-works)
- To learn how MongoDB combines multikey index bounds to improve performance, see Multikey Index Bounds. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/)
- To help you better understand the performance of your pipeline, you can view your pipeline's explain plan. You can view the explain plan at any point while creating or editing your pipeline. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline-builder/view-pipeline-explain-plan.md)
- To view your full explain plan as raw JSON, select the Raw Output view. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline-builder/view-pipeline-explain-plan.md#steps)
- To help you better understand the performance of your query, you can view your query's explain plan. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/query-plan.md)
- Create a 2d index on the `address` field. Specify the following location bounds: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2d/create/define-location-range.md#procedure)
- To use [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain), append one of the aforementioned methods to [`db.collection.explain()`:](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#description)
- To see the list of operations supported by [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain), run: — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#help)
- To determine whether a query is a covered query, use the db.collection.explain() or the explain() method. See Covered Queries. — [source](https://www.mongodb.com/docs/manual/core/query-optimization/)
- To determine whether a query is a covered query, use the [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) or the [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method. See [Covered Queries.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-covered-queries) — [source](https://www.mongodb.com/docs/manual/core/query-optimization.md#explain-results)
- To learn about important explain result fields and how to interpret them, see [Interpret Explain Plan Results.](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#std-label-interpret-explain-plan) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md)
- To learn about important explain result fields and how to interpret them, see Interpret Explain Plan Results. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- To learn how Queryable Encryption works, see [Queryable Encryption Fundamentals.](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals.md#std-label-qe-fundamentals) — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/quick-start.md#learn-more)
- To learn how project works, see the `project` entry in the [MongoDB Manual.](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#std-label-find-projection) — [source](https://www.mongodb.com/docs/compass/query/project.md#learn-more)
- Use `kyber` to run multiple workloads in the same VM or in your own data center. `kyber` improves the I/O interpolation under contention, and reduces the impact of noisy neighbors. Additionally, `kyber` works efficiently in self hosted situations, such as on-premises virtualization and collocated workloads in one large cloud VM. However, `kyber` is only available on linux kernels starting in version 4.12. — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-operations.md#linux)
- Avoid modifying the [`wiredTigerEngineRuntimeConfig`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.wiredTigerEngineRuntimeConfig) unless under the direction from MongoDB engineers as this setting has major implication across both WiredTiger and MongoDB. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#wiredtiger-parameters)

## Examples and snippets

- ```javascript — `"op" : "query",` … — [source](https://www.mongodb.com/docs/manual/reference/database-profiler.md#find-operation)
- ````text — `## Summary` … — [source](https://www.mongodb.com/docs/compass/query-with-natural-language/compass-ai-assistant.md#explain-plan)
- ```javascript — `"t":{` … — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#slow-operation)
- ```javascript — `"t": {` … — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#view)
- ```javascript — `queryPlanner: {` … — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- ```javascript — `queryPlanner: {` … — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- ```json — `<Timestamp> COMMAND <query>` … — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting.md#alert-conditions)
- ```none — `"version" : 1,` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md#classic-execution-engine)
- ```javascript — `"t":{"$date":"2026-08-14T13:36:19.194-04:00"},"s":"D1",` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/toggle-logging.md#querystats-output-included)
- ```javascript — `winningPlan: {` … — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- ```javascript — `executionStats: {` … — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- ```javascript — `version: '2',` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md#find-cache-entry-details-for-a-query-hash)
- ```text — `"explainVersion": "1",` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```javascript — `db.people.find(` … — [source](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#control-index-use-with-hint)
- ```javascript — `db.people.explain("executionStats").find(` … — [source](https://www.mongodb.com/docs/manual/tutorial/measure-index-use.md#control-index-use-with-hint)
- ```javascript — `db.runCommand( {` … — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#hide-an-index-from-the-query-planner)
- ```javascript — `// Query Operation 1` … — [source](https://www.mongodb.com/docs/manual/core/query-plans.md#plancachekey)
- ```javascript — `// Query Operation 2` … — [source](https://www.mongodb.com/docs/manual/core/query-plans.md#plancachekey)
- ```javascript — `db.<collection>.dropIndex("<indexName>")` … — [source](https://www.mongodb.com/docs/manual/core/indexes/drop-index.md#drop-a-single-index)
- ```javascript — `db.movies.explain().count( { year: { $gt: 2000 } } )` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#queryplanner-mode)
- ```javascript — `db.pizzaOrders.explain().find(` … — [source](https://www.mongodb.com/docs/manual/core/query-shapes.md#matching-query-shapes)
- ```javascript — `db.pizzaOrders.explain().find(` … — [source](https://www.mongodb.com/docs/manual/core/query-shapes.md#different-query-shape)
- ```javascript — `db.movies.explain().find( { rated: "PG" } ).finish().queryPlanner.winningPlan` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#access-the-explain-results-with-finish-method)
- ```javascript — `db.runCommand( {` … — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#change-index-properties)
- ```javascript — `db.movies.find(` … — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- ```javascript — `key: {` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#transformed-example)
- ```javascript — `{ // Plan Cache Entry 1` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md#return-information-for-all-entries-in-the-query-cache)
- ```java — `var explainCommand = new Document("explain", new Document()` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#use-secondary-indexes-to-improve-sort-performance)
- ```javascript — `db.sensorData.explain( "executionStats" ).aggregate( [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#use-secondary-indexes-to-improve-sort-performance)
- ```javascript — `db.getCollection( 'sensorData' ).explain( "executionStats" ).aggregate( [` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```javascript — `const explainResult = await database.command({` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#use-secondary-indexes-to-improve-sort-performance)
- ```python — `explain_result = database.command(` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#use-secondary-indexes-to-improve-sort-performance)
- ```csharp — `// Indexes on ``timeField`` descending are more performant because they` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```java — `// Indexes on ``timeField`` descending are more performant because they` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```javascript — `// Indexes on ``timeField`` descending are more performant because they` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```python — `# Indexes on ``timeField`` descending are more performant because they` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- ```javascript — `db.runCommand(` … — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#allplansexecution-mode)
- ```javascript — `db.runCommand({` … — [source](https://www.mongodb.com/docs/manual/core/index-ttl.md#convert-a-non-ttl-single-field-index-into-a-ttl-index)
- ```text — `atlas clusters search indexes create [indexName] [options]` … — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-create.md#syntax)
- ```javascript — `db.collection.find().explain()` … — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- ```none — `db.collection.explain().<method(...)>` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#description)
- ```javascript — `db.movies.explain().remove( { rated: "PG" }, { justOne: true } )` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#description)
- ```javascript — `db.movies.explain().aggregate(` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#return-information-on-aggregation-pipeline-operation)
- ```text — `Interpret this explain plan for me.` … — [source](https://www.mongodb.com/docs/compass/query-with-natural-language/compass-ai-assistant.md#explain-plan)
- ```text — `atlas deployments search indexes create [indexName] [options]` … — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-create.md#syntax)
- ```javascript — `db.products.find(` … — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#example)
- ```javascript — `db.movies.explain( "allPlansExecution" ).findAndModify( {` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#allplansexecution-mode)
- ```javascript — `var cursor = db.users.find(` … — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#explain-with-options)
- ```javascript — `db.inventory.find(` … — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/limit-number-of-items-scanned-for-text-search.md#view-number-of-documents-examined)
- ```none — `'$lookup': {` … — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#execution-plan-statistics-for-query-with-lookup-pipeline-stage)
- ```javascript — `stage: 'OR',` … — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#or-expression)
- ```javascript — `db.runCommand(` … — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#executionstats-mode)
- ```none — `$densify: {` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#syntax)
- ```javascript — `db.weather.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-time-series-data)
- ```javascript — `db.coffee.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-the-full-range-of-values)
- ```javascript — `db.coffee.aggregate( [` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-values-within-each-partition)
- ```python — `client = MongoClient(CONNECTION_STRING)` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#before-you-begin)
- ```javascript — `"ns" : <string>,` … — [source](https://www.mongodb.com/docs/manual/reference/command/collStats.md#output)
- ```javascript — `timestamp: ISODate("2024-06-17T10:00:00Z"),` … — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices.md#use-standard-embedded-fields-best-practices)
- ```shell — `atlas api atlasSearch deleteIndexByName --version 2024-05-30 --clusterName [clusterName] --collectionName [col` … — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-api-atlasSearch-deleteIndexByName.md#examples)
- ```javascript — `db.<collection>.aggregate(` … — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes.md#syntax)
- ```javascript — `db.<collection>.createIndex(` … — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/control-text-search-results.md)
- ```javascript — `db.getSiblingDB("examples").runCommand(` … — [source](https://www.mongodb.com/docs/manual/reference/command/setIndexCommitQuorum.md#examples)

## Measurements and reference values

- nreturned:4 protocol:op_query 358ms — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting/)
- For example, on a system with a total of 4GB of RAM the WiredTiger cache uses 1.5GB of RAM (`0.5 * (4GB - 1GB) = 1.5 GB`). When providing a specific cache size ensure the RAM does not exceed the bounds of 0.256GB to 10000GB. — [source](https://www.mongodb.com/docs/manual/administration/production-notes.md#cache-configuration-settings)

## Problems, failure modes and limitations

- | Field | Description | | --- | --- | | `version` | A number that indicates the query engine used to complete the query. `1` indicates that the classic engine was used.; `2` indicates that the [slot-based query execution engine](https://www.mongodb.com/docs/manual/reference/sbe.md#std-label-sbe-landing) was used. | | `createdFromQuery` | A document that contains the specific query that resulted in this cache entry. For example: `{ "query" : <document>, "sort" : <document>, "projection" : <document> }` | | `isActive` | A boolean that indicates whether the entry is active or inactive. If active, — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats.md#classic-execution-engine)
- | Field | Type | Literal or Normalized | Description | | --- | --- | --- | --- | | `key` | Document | Literal | Contains the query shape and additional query attributes that group a set of queries together | | `key.queryShape` | Document | Literal | Contains attributes used to group similar queries together. For more information, see [Query Shape.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/querystats.md#std-label-queryStats-queryShape) | | `key.client` | Document | Literal | Describes client information associated with the key | | `key.client.application` | Document | — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#output)
- | **MongoDB Version** | **Changes** | | --- | --- | | 6.1 | Slow operation log messages include [cache refresh time fields.](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-cache-refresh-times) | | 6.2 | Slow operation log messages include a `queryFramework` field that indicates which query engine executed the query: `queryFramework: "classic"` indicates that the classic engine executed the query.; `queryFramework: "sbe"` indicates that the slot-based query execution engine executed the query. | | 6.3 | Slow operation log messages and [database profiler](ht — [source](https://www.mongodb.com/docs/manual/reference/log-messages.md#version-specific-changes)
- Before dropping, check prefix redundancy (a compound index { a:1, b:1 } serves queries on { a:1 }), and after dropping watch the slow-query log for COLLSCAN and verify critical query shapes with explain('executionStats'), since the planner may switch to a different existing index. — [source](https://www.netdata.cloud/guides/mongodb/mongodb-unused-indexes/)
- planSummary is a string in both system.profile documents and slow-query log entries that summarises the winning plan (e.g. 'COLLSCAN' or 'IXSCAN { a: 1, _id: -1 }'). A COLLSCAN with keysExamined 0 and docsExamined far above nreturned signals a missing index; the docsExamined:docsReturned ratio near 1:1 is ideal. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- | Method | Availability | Description | | --- | --- | --- | | Use the Atlas Query Profiler | M10+ Atlas clusters | The Atlas Query Profiler shows long-running operations and performance statistics. For more information, see [Monitor Query Performance with the Query Profiler.](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#std-label-profile-database) | | Enable the Database Profiler | Atlas clusters and self-hosted deployments | When enabled, the database profiler stores information about slow queries in the [`system.profile`](https://www.mongodb.com/docs/manual/reference/system- — [source](https://www.mongodb.com/docs/manual/tutorial/evaluate-operation-performance.md#analyze-a-slow-query)
- When a query shape has query knobs set through setQuerySettings or setParameter, slow query log entries include a queryKnobs document. The document shows the effective value of each knob and where the value comes from, with the same shape as the explain output. For details, see Query Knobs. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- A SORT stage means an in-memory sort. In stages that can spill, usedDisk true (added in 5.3) shows the sort went to disk, which is slow; the usual fix is a compound index whose order supports the sort so the SORT stage disappears. — [source](https://oneuptime.com/blog/post/2026-03-31-mongodb-read-executionstats-output-explain/view)
- From 8.0 the explain output carries planCacheShapeHash (a copy of queryHash, which is deprecated and slated for removal) and planCacheKey. planCacheKey depends on both the plan cache query shape and the available indexes. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Starting in MongoDB 8.0, the existing `queryHash` field is duplicated in a new field named `planCacheShapeHash`. If you're using an earlier MongoDB version, you'll only see the `queryHash` field. Future MongoDB versions will remove the deprecated `queryHash` field, and you'll need to use the `planCacheShapeHash` field instead. — [source](https://www.mongodb.com/docs/manual/core/query-plans.md#plancacheshapehash)
- A hexadecimal string that represents the hash of the [plan cache query shape](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-plan-cache-query-shape) and is dependent only on the plan cache query shapes. `planCacheShapeHash` can help identify slow queries (including the query filter of write operations) with the same plan cache query shape. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - If `false` or `0`, the stage may still have results to return. For example, consider a query with a limit whose execution stages consists of a `LIMIT` stage with an input stage of `IXSCAN` for the query. If the query returns more than the specified limit, the `LIMIT` stage will report `isEOF: 1`, but its underlying `IXSCAN` stage will report `isEOF: 0`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- To check if MongoDB must perform an in-memory sort, append cursor.explain() to the query and check the explain results. If the query plan contains a SORT stage, then MongoDB must perform an in-memory sort operation subject to the 100 megabyte memory limit. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse/)
- | Index Property | Description | | --- | --- | | `expireAfterSeconds` | The number of seconds that determines the expiration threshold of a [TTL Collection.](https://www.mongodb.com/docs/manual/tutorial/expire-data.md#std-label-ttl-collections) If successful, the command returns a document that contains: `expireAfterSeconds_new`, the new value for `expireAfterSeconds`; `expireAfterSeconds_old`, the old value for `expireAfterSeconds`, if the index had a value for `expireAfterSeconds` before. Modifying the index option `expireAfterSeconds` resets the [`$indexStats`](https://www.mongodb.com/docs/ — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#change-index-properties)
- If MongoDB cannot use an index or indexes to obtain the sort order, the results include a `SORT` stage indicating an in-memory sort operation. If the explain plan does not contain an explicit `SORT` stage, then MongoDB used an index to obtain the sort order. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#sort-stage)
- | Field | Type | Description | | --- | --- | --- | | [setIndexCommitQuorum](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#std-label-setIndexCommitQuorum-cmd-coll) | `string` | The name of the collection for which the indexes are being built. | | [indexNames](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#std-label-setIndexCommitQuorum-cmd-indexNames) | `array` | An array of in-progress index builds to modify. Each element of the array must be the *name* of the index. The indexes specified to `indexNames` must be the entire set of i — [source](https://www.mongodb.com/docs/manual/reference/command/setIndexCommitQuorum.md#command-fields)
- | Field | Type | Description | | --- | --- | --- | | `key` | document | Specifies the index's fields. For each field, specify a key-value pair in which the key is the name of the field to index and the value is either the index direction or [index type](https://www.mongodb.com/docs/manual/core/indexes/index-types.md#std-label-index-types). If specifying direction, specify `1` for ascending or `-1` for descending. MongoDB supports several different index types, including: [text](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-feature-text); [geospatial — [source](https://www.mongodb.com/docs/manual/reference/command/createIndexes.md#command-fields)
- MongoDB automatically enables block processing for eligible time series queries. You cannot manually specify whether a query uses block processing. To see if your time series query uses block processing, see [`stages`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.slotBasedPlan.stages) in the explain plan output. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#block-processing)
- However, the following query operation, which by default uses the "simple" binary collator, cannot use the index and requires a `COLLSCAN`. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex.md#create-indexes-with-collation)
- | `$exists` Query | Using a Sparse Index | Using a Non-Sparse Index | | --- | --- | --- | | `{ $exists: true }` | Most efficient. MongoDB can make an exact match and does not require a `FETCH`. | More efficient than queries without an index, but still requires a `FETCH`. | | `{ $exists: false }` | Cannot use the index and requires a `COLLSCAN`. | Requires a `FETCH`. | — [source](https://www.mongodb.com/docs/manual/reference/operator/query/exists.md#use-a-sparse-index-to-improve-exists-performance)
- Cannot use the index and requires a COLLSCAN. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/exists/)
- Slow query log messages contain new metrics if the query execution writes temporary files to disk. These metrics are prefixed by the query execution stage that caused the query to exceed the memory limit. For example, sortSpills indicates the number of times that the sort stage of query execution wrote temporary files to disk. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- Specify `precision` and limit it when possible. Every digit increases storage overhead and has a high impact on searchable range and index generation. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- | Parameter | Type | Description | | --- | --- | --- | | `wildcardProjection` | document | Optional. Allows users to include or exclude specific field paths from a [wildcard index.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard.md#std-label-wildcard-index-core) This option is only valid when you create an [wildcard index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard.md#std-label-wildcard-index-core) on all document fields. You cannot specify the `wildcardProjection` option when you create a wildcard index on a specific field path and — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndexes.md#options-for-wildcard-indexes)
- If the query does not join the conditions on the array field with `$elemMatch`, MongoDB cannot intersect the multikey index bounds. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#query-without-elemmatch)
- If MongoDB cannot compound the two bounds, MongoDB constrains the index scan by the bound on the leading field. In this example, the leading field is `temperature`, resulting in a constraint of `temperature: [ [ 80, Infinity ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#compound-bounds-for-a-multikey-index)
- If your query specifies `$elemMatch` on fields that diverge from a common path, MongoDB **cannot** compound the bounds of index keys from the same array. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-elemmatch-on-diverging-field-paths)
- MongoDB cannot compound the index bounds and the `"ratings.scores.q2"` field is unconstrained during the index scan. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-elemmatch-on-diverging-field-paths)
- | Parameter | Type | Description | | --- | --- | --- | | `keyPatterns` | document | An array containing index specification documents. Each document contains field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of `1`; for descending index, specify a value of `-1`. .. include:: /includes/indexes/wildcard-use-wc-methods.rst | | `options` | document | Optional. A document that contains a set of options that controls the creation of the indexes. See [Options](https://www.mongodb.com/docs — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndexes.md#parameters)
- "Range" filters scan fields. The scan doesn't require an exact match, which means range filters are loosely bound to index keys. To improve query efficiency, limit the range bounds and use equality matches to reduce the number of documents to scan. — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-rule/)
- Explain output is limited by the maximum [Nested Depth for BSON Documents](https://www.mongodb.com/docs/manual/reference/limits.md#mongodb-limit-Nested-Depth-for-BSON-Documents), which is 100 levels of nesting. Explain output that exceeds the limit is truncated. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- If the index does not exist, the command errors with the message `"cannot find index <name|keyPattern> for ns <db.collection>"`. — [source](https://www.mongodb.com/docs/manual/reference/command/collMod.md#change-index-properties)
- Sort stages, counted separately by sort type and by whether the sort has a limit. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- If the argument resolves to a value of `null` or refers to a field that is missing, [`$asin`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin.md#mongodb-expression-exp.-asin) returns `null`. If the argument resolves to `NaN`, [`$asin`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin.md#mongodb-expression-exp.-asin) returns `NaN`. If the argument resolves to a value outside the bounds of `[-1, 1]` inclusive, [`$asin`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin.md#mongodb-expression-exp.-asin) throws an error. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin.md#behavior)
- Specify minimum and maximum (inclusive) queryable values for a field when possible, as smaller bounds improve query efficiency. If querying values outside of these bounds, MongoDB returns an error. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#configure-encrypted-fields-for-optimal-search-and-storage)
- | Field | Type | Description | | --- | --- | --- | | [min and max](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#std-label-qe-field-min-max) | Same as field `bsonType` | Required if `bsonType` is `decimal` or `double`. Optional but highly recommended if it is `int`, `long`, or `date`. Defaults to the minimum and maximum values of the `bsonType`. When possible, specifying bounds on a query improves performance. If querying values outside of these inclusive bounds, MongoDB returns an error. | — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/qe-create-encryption-schema.md#steps)
- If the argument resolves to a value of `null` or refers to a field that is missing, [`$acos`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos.md#mongodb-expression-exp.-acos) returns `null`. If the argument resolves to `NaN`, [`$acos`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos.md#mongodb-expression-exp.-acos) returns `NaN`. If the argument resolves to a value outside the bounds of `[-1, 1]` inclusive, [`$acos`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos.md#mongodb-expression-exp.-acos) throws an error. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos.md#behavior)

## Comparisons and alternatives

- | Field | Field Type | Necessity | Description | | --- | --- | --- | --- | | `setQuerySettings` | document or string | Required | You can provide either: The same fields as those in a [`find`](https://www.mongodb.com/docs/manual/reference/command/find.md#mongodb-dbcommand-dbcmd.find), [`distinct`](https://www.mongodb.com/docs/manual/reference/command/distinct.md#mongodb-dbcommand-dbcmd.distinct), or [`aggregate`](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#mongodb-dbcommand-dbcmd.aggregate) command, and a `$db` field with the database associated with the original command — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md#command-fields)
- A low docsExamined/nReturned ratio does not guarantee a fast query: a non-selective index can be slower than a scan, and a query that returns a large share of the collection may rightly choose a COLLSCAN. IXSCAN with high cost usually points to index selectivity rather than a missing index. — [source](https://www.netdata.cloud/guides/mongodb/mongodb-slow-query-collscan/)
- | Option | Description | | --- | --- | | allowDiskUse | Whether or not pipelines that require more than 100 megabytes of memory to execute write to temporary files on disk. For details, see [`cursor.allowDiskUse()`.](https://www.mongodb.com/docs/manual/reference/method/cursor.allowdiskuse.md#mongodb-method-cursor.allowDiskUse) | | allowPartialResults | For queries against a sharded collection, allows the command (or subsequent getMore commands) to return partial results, rather than an error, if one or more queried shards are unavailable. | | awaitData | If the cursor is a a tailable-await cur — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#options)
- Unlike the [`explain.queryPlanner.planCacheShapeHash`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.planCacheShapeHash), the [`explain.queryPlanner.planCacheKey`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.planCacheKey) is a function of both the plan cache query shape and the currently available indexes for that shape. Specifically, if indexes that can support the query shape are added or dropped, the `planCacheKey` value may change but the `planCacheShapeHash` value wouldn't change. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Recommended practice: compare explain('executionStats') (totalDocsExamined, executionTimeMillis) for hinted vs unhinted runs; use a hint to work around a stale cached plan or misleading selectivity, not as a permanent fix without addressing the missing or poorly designed index, since a forced index can worsen as data changes. — [source](https://oneuptime.com/blog/post/2026-03-31-mongodb-hint-force-index/view)
- For example, the following aggregation operation can be fulfilled by the tree of query plan execution rather than using the aggregation pipeline. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - Keys Examined (`keysExamined`): Number of index keys scanned for the query. If this metric is `0` for a query that includes filter conditions, it's highly likely there is no index and MongoDB scanned the entire collection. This is a primary cause of slowness. If Docs Examined is very high and Keys Examined is `0` or very low compared to Docs Examined, you're likely scanning the collection or a very unselective index. To learn more, see [Indexes.](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) — [source](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#find-slow-queries-with-the-query-profiler)
- The second compound index, `{ rated: 1, year: 1 }`, is therefore the more efficient index for supporting the example query, as the MongoDB server only needs to scan `235` [`index keys`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) to find all matching documents using this index, compared to `246` when using the compound index `{ year: 1, rated: 1 }`. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- Fewer documents examined does not guarantee a faster query. Percona's sort example examined fewer documents but ran slower because an extra in-memory SORT stage was needed; Pythian's final index (129 keys vs 82) removed the SORT stage at the cost of a worse key ratio and ran 3 ms vs 2 ms. Check execution time and SORT stages alongside the ratios. — [source](https://www.percona.com/blog/2018/09/06/mongodb-investigate-queries-with-explain-index-usage-part-2/)
- | Parameter | Type | Description | | --- | --- | --- | | `unique` | boolean | Optional. Specifies that each index specified in the `keyPatterns` array is a [unique index](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique). Unique indexes will not accept insertion or update of documents where the index key value matches an existing value in the index. Specify `true` to create a unique index. The default value is `false`. The option is *unavailable* for [hashed indexes.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-hashed.md#std-label-inde — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndexes.md#options-for-all-index-types)
- | Counter | Description | | --- | --- | | `collscanNoFilter``collscanWithFilter` | Collection scan stages, counted separately based on whether the stage applies a filter. | | `ixscanNoFilter``ixscanWithFilter` | Index scan stages, counted separately based on whether the stage applies a filter. | | `fetchNoFilter``fetchWithFilter` | Fetch stages, counted separately based on whether the stage applies a filter. | | `andHashNoFilter``andHashWithFilter` | Hash-based index intersection stages, counted separately based on whether the stage applies a filter. | | `andSorted` | Sorted index intersection — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#node-counters)
- `cursor.explain()` defaults to `queryPlanner`, unlike the [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) command, which defaults to `allPlansExecution`. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- | Field | Type | Description | | --- | --- | --- | | `scale` | number | Optional. The scale factor for the various size data. The `scale` defaults to 1 to return size data in bytes. To display kilobytes rather than bytes, specify a `scale` value of `1024`. If you specify a non-integer scale factor, MongoDB uses the integer part of the specified factor. For example, if you specify a scale factor of `1023.999`, MongoDB uses `1023` as the scale factor. Starting in version 4.2, the output includes the `scaleFactor` used to scale the size values. | | `indexDetails` | boolean | Optional. If `true`, — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.stats.md#fields)
- [MongoDB Search](https://www.mongodb.com/docs/atlas/atlas-search/) offers advanced full-text search capabilities, including [configurable dynamic indexing](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-configure-dynamic-mappings). We recommend using [MongoDB Search indexes](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-manage-indexes) instead of text indexes. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/create-wildcard-text-index.md)
- If you run this example, the order of documents in your results might differ from the order of documents on this page because the aggregation pipeline does not contain a sort stage. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/unpack-arrays.md#steps)

## Facts and statements

- A boolean that specifies whether MongoDB applied an [index filter](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-index-filters) for the [plan cache query shape.](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-plan-cache-query-shape) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- executionStats.executionTimeMillis covers plan selection (including the trial phase) plus execution, excludes network transfer, and is not necessarily representative of real query time: with a cached plan or cursor.hint(), plan selection is bypassed and actual time is lower than the reported value. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- If the query planner selects an index, the explain result includes a `IXSCAN` stage. The stage includes information such as the index key pattern, direction of traversal, and index bounds. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#collection-scan)
- Explain output shape depends on the engine: classic-engine plans put the stage tree at winningPlan.stage with nested inputStage, while slot-based-engine (SBE) plans put it under winningPlan.queryPlan and carry a planNodeId per stage. The docs warn that examples mix both shapes and real output may differ significantly. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The three explain('executionStats') counters used to judge an index are nReturned, totalKeysExamined and totalDocsExamined. A COLLSCAN shows totalKeysExamined 0 and totalDocsExamined equal to the collection size (21349 docs scanned to return 3809 in the MongoDB docs example). — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- - [`queryPlanner.winningPlan.stage`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.stage) displays `COLLSCAN` to indicate a collection scan. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- MongoDB runs the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) to choose the winning plan for the operation under evaluation. [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) returns the [`queryPlanner`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner) information for the evaluated method. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#queryplanner-mode)
- If the query optimizer considered more than one plan, [`executionStats`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats) information also includes the *partial* execution information captured during the [plan selection phase](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) for both the winning and rejected candidate plans. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#allplansexecution-mode)
- planSummary: COLLSCAN keysExamined:0 — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting/)
- If the `queryPlanner.winningPlan.inputStage.stage` is either `CLUSTERED_IXSCAN` or `IXSCAN`, the index was used. For more information on the explain plan output, see [Explain Results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- The `winningPlan.queryPlan.inputStage.stage` is `DISTINCT_SCAN`, which indicates that the index was used. For more information on the explain plan output, see [Explain Results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-secondary-index.md#last-point-queries-on-time-series-collections)
- - [`queryPlanner.winningPlan.inputStage.stage`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.inputStage) displays `IXSCAN` to indicate index use. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- The total number of index items scanned during queries and query-plan evaluation. This counter is the same as [`totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) in the output of [`explain()`.](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- If MongoDB uses indexes for an [`$or`](https://www.mongodb.com/docs/manual/reference/operator/query/or.md#mongodb-query-op.-or) expression, the result will include the `OR` stage with an [`explain.queryPlanner.winningPlan.inputStages`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.inputStages) array that details the indexes; e.g.: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#or-expression)
- For more information on `planCacheShapeHash` and `planCacheKey`, see [planCacheShapeHash and planCacheKey.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-hash-plan-cache-key) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A boolean that indicates if the winningPlan is in the plan cache. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- The returned [`explain.executionStats`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats) information details the execution of the winning plan. To include `executionStats` in the results, you must run the explain in either: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#executionstats)
- - [allPlansExecution](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-allPlansExecution) verbosity mode. Use `allPlansExecution` mode to include partial execution data captured during [plan selection.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#executionstats)
- Number of documents returned by the winning query plan. [`nReturned`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.nReturned) corresponds to the `n` field returned by `cursor.explain()` in earlier versions of MongoDB. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Details the completed execution of the winning plan as a tree of stages; i.e. a stage can have an `inputStage` or multiple `inputStages`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - If you see `"planSummary": "COLLSCAN":` in the query log, the query performed a collection scan and did not use an index. This is a strong signal to add an [index](https://www.mongodb.com/docs/manual/indexes.md#std-label-indexes) or rewrite the query. — [source](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#find-slow-queries-with-the-query-profiler)
- If keysExamined is much higher than nreturned, the query scans many index keys; consider adjusting the index. For writes, keysExamined and docsExamined include reads from write-conflict retries, so they can exceed documents matched or modified. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- Number of documents examined during query execution. Common query execution stages that examine documents are `COLLSCAN` and `FETCH`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - [`executionStats.nReturned`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.nReturned) displays `3809` to indicate that the winning query plan returns 3,809 documents. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- The total number of documents scanned during queries and query-plan evaluation. This counter is the same as [`totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) in the output of [`explain()`.](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- - [`executionStats`](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats), which details the execution of the winning plan and the rejected plans. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- The verbosity mode (i.e. `queryPlanner`, `executionStats`, `allPlansExecution`) determines whether the results include [`executionStats`](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) and whether [`executionStats`](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) includes data captured during [plan selection.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- | Subdocument | Description | | --- | --- | | `patterns` | Counts the overall shape of each winning plan. The patterns are mutually exclusive, so each query execution increments at most one pattern counter. | | `nodes` | Counts the types of plan stages that appear in each winning plan. The node counters are not mutually exclusive, so one query execution can increment several of them. | | `accessPaths` | Counts the data access paths and index bounds that each winning plan uses. The access path counters are not mutually exclusive, so one query execution can increment several of them. | — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#plan-shape-counters)
- If you see "planSummary": "COLLSCAN": in the query log, the query performed a collection scan and did not use an index. This is a strong signal to add an index or rewrite the query. — [source](https://www.mongodb.com/docs/atlas/tutorial/query-profiler/)
- [`explain.queryPlanner`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner) information details the plan selected by the [query optimizer.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#queryplanner)
- These examples may combine the output structures of the classic and slot-based execution engines. They are not meant to be representative. Your output may differ significantly. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#queryplanner)
- Time in milliseconds the query planner spent on query optimization. This result doesn't include time spent optimizing inner [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) queries. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A document that details the plan selected by the [query optimizer.](https://www.mongodb.com/docs/manual/core/query-plans.md) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A document that details the plan selected by the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md). MongoDB presents the plan as a tree of stages. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Array of candidate plans considered and rejected by the query optimizer. The array can be empty if there were no other candidate plans. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- queryPlanner.winningPlan.stage displays COLLSCAN to indicate a collection scan. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- If the query planner selects a collection scan, the explain result includes a `COLLSCAN` stage. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#collection-scan)
- The explain results for a query differ based on which query engine was used. For example, explain results for queries executed using the slot-based execution engine include the [`explain.queryPlanner.winningPlan.slotBasedPlan`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.winningPlan.slotBasedPlan) field. — [source](https://www.mongodb.com/docs/manual/reference/sbe.md#check-query-explain-results)
- MongoDB runs the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) to choose the winning plan, executes the winning plan to completion, and returns statistics describing the execution of the winning plan. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#executionstats-mode)
- "planSummary" : "COLLSCAN", — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- - [`queryPlanner`](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-queryPlanner), which details the plan selected by the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-read-operations-query-optimization) and lists the rejected plans. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- ```javascript [ { "opid": "12345", "secs_running": 5, "active": true, "ns": "sample_mflix.movies", "command": { "find": "movies", "filter": { "title": { "$regex": "The" } } }, "planSummary": "COLLSCAN", "locks": { ... }, "client": "203.0.113.25:43210" } ] ``` — [source](https://www.mongodb.com/docs/manual/tutorial/monitor-slow-queries.md#steps)
- explain ignores existing plan cache entries and does not create a new one. A plan taken from the cache shows isCached: true in explain("executionStats") (per Percona), and fromPlanCache: true in the profiler. — [source](https://www.mongodb.com/docs/current/core/query-plans/)
- Number of index entries scanned. [`explain.executionStats.totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) corresponds to the `nscanned` field returned by `cursor.explain()` in earlier versions of MongoDB. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- MongoDB documents a two-counter heuristic for a bad filter: if executionStats.totalDocsExamined is much greater than executionStats.nReturned, the index is ineffective; if the two are equal, MongoDB examined only the documents it returned, which indicates an effective index. — [source](https://www.mongodb.com/docs/manual/tutorial/explain-slow-queries/)
- Instead, MongoDB uses the wildcard index to support only one of the query predicates. MongoDB automatically chooses which predicate to support based on relevant wildcard index paths. The unsupported query predicates are shown in the [`rejectedPlans`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.queryPlanner.rejectedPlans) of the [explain results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/reference/restrictions.md#multi-field-query-predicates)
- In general, if [`keysExamined`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.keysExamined) is much higher than [`nreturned`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.nreturned), the database is scanning many index keys to find the result documents. Consider creating or adjusting indexes to improve query performance.. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler.md#output-fields)
- A boolean that indicates that the entire aggregation pipeline operation was optimized away, and instead, fulfilled by a tree of query plan execution stages. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- This field is `true` for a maximum of one plan between the winning plan and the rejected plans. If the query has no cached plan, the field is `false` for the winning plan and the rejected plans. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- A significant difference between the `numKeysEstimate` and the `costEstimate` can indicate issues with the `winningPlan`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Rejected plans have the same fields as `explain.queryPlanner.winningPlan`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Double that represents the score of the winning plan chosen by the multi-planner. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- MongoDB's docs warn that explain plan results are subject to change between MongoDB versions, so stored ratio baselines should be re-measured after upgrades. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- MongoDB runs the [query optimizer](https://www.mongodb.com/docs/manual/core/query-plans.md) to choose the winning plan and executes the winning plan to completion. In `"allPlansExecution"` mode, MongoDB returns statistics describing the execution of the winning plan as well as statistics for the other candidate plans captured during [plan selection.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#allplansexecution-mode)
- - [`executionStats.totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) displays `0` to indicate that this query is not using an index. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- MongoDB scanned `246` index keys ([`executionStats.totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined)) to return `235` matching documents ([`executionStats.nReturned`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.nReturned)). — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- MongoDB scanned `235` index keys ([`executionStats.totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined)) to return `235` matching documents ([`executionStats.nReturned`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.nReturned)). — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- In some cases, the query planner uses a `DISTINCT_SCAN` index plan that returns one document per index key value. `DISTINCT_SCAN` executes faster than `IXSCAN` if there are multiple documents per key value. However, index scan parameters might affect the time comparison of `DISTINCT_SCAN` and `IXSCAN`. — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#indexes)
- The cursor.explain("executionStats") and the db.collection.explain("executionStats") methods provide statistics about the performance of a query. These statistics can be useful in measuring if and how a query uses an index. See db.collection.explain() for details. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- queryPlanner.winningPlan.inputStage.stage displays IXSCAN to indicate index use. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- The number of index keys examined is indicated in the [`totalKeysExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalKeysExamined) field. Queries that examine more index keys generally take longer to complete. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text/limit-number-of-items-scanned-for-text-search.md#view-number-of-documents-examined)
- A hash of the key for the plan cache entry associated with the query. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- By default, [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) runs in `queryPlanner` verbosity mode. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#queryplanner-mode)
- The following example runs [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) in `"queryPlanner"` verbosity mode to return the query planning information for the specified [`count()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.count.md#mongodb-method-db.collection.count) operation: — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#queryplanner-mode)
- The execution of this explain will *not* modify data but runs the query predicate of the update operation. For candidate plans, MongoDB returns the execution information captured during the [plan selection phase.](https://www.mongodb.com/docs/manual/core/query-plans.md#std-label-query-plans-query-optimization) — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#allplansexecution-mode)
- - `SHARD_MERGE` for merging results from shards — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- - `SHARDING_FILTER` for filtering out orphan documents from shards — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- For unsharded collections, `explain` returns the following `executionStats` information: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- If a document is examined multiple times during query execution, [`explain.executionStats.totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) counts each examination. That is, [`explain.executionStats.totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) is *not* a count of the total number of *unique* documents examined. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Starting in MongoDB 5.1, a stage can have these input stages: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Each `inputStage` can have different fields depending on the value of `inputStage.stage`. The following table describes possible fields and what stages they can appear in. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Third-party guides add numeric thresholds to the docsExamined/nReturned ratio: Netdata calls 1:1 ideal and above 100:1 severe inefficiency. These figures are blog rules of thumb; the MongoDB docs give no numeric cutoff. — [source](https://www.netdata.cloud/guides/mongodb/mongodb-slow-query-collscan/)
- An efficient indexed query examines about as many keys and documents as it returns. In the MongoDB docs example, an index on year gives nReturned = totalKeysExamined = totalDocsExamined = 3809, which the docs call 'a very efficient query'. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- For more information on query plans, see [Explain Results.](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- The [`explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) method returns a document with the query plan and, optionally, the execution statistics. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- - The [`db.collection.find().explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) returns the `explain()` information on the query plan. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#db-collection-explain-find)
- Counts of the data access paths and index bounds that the winning plans use. A single winning plan can match multiple access path counters. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- Counts the data access paths and index bounds that each winning plan uses. The access path counters are not mutually exclusive, so one query execution can increment several of them. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- A string that specifies whether the cursor uses a collection scan (`COLLSCAN`) or an index scan (`IXSCAN { ... }`). — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- | Access Path | Counters | | --- | --- | | Collection scan | `collscan`; `collscanProject`; `collscanProjectSort`; `collscanProjectSortProject`; `collscanSort`; `collscanSortProject`; `collscanSortProjectSort` | | Index scan with a fetch | `ixscanFetch`; `ixscanFetchProject`; `ixscanFetchProjectSort`; `ixscanFetchProjectSortProject`; `ixscanFetchSort`; `ixscanFetchSortProject`; `ixscanFetchSortProjectSort`; `ixscanFetchSortMerge`; `ixscanFetchSortMergeProject` | | Index scan with an `$or` | `ixscanFetchOr`; `ixscanFetchOrProject`; `ixscanFetchOrProjectSort`; `ixscanFetchOrSort`; `ixscanFetchOr — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats.md#pattern-counters)
- This document appears if the query used the [slot-based execution query engine.](https://www.mongodb.com/docs/manual/reference/sbe.md#std-label-sbe-landing) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- - Docs Examined (`docsExamined`): Number of documents MongoDB inspected for the query. If Docs Examined is significantly larger than Docs Returned, this often means that: — [source](https://www.mongodb.com/docs/atlas/tutorial/query-profiler.md#find-slow-queries-with-the-query-profiler)
- - [`executionStats.totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) displays `21349` to indicate that MongoDB had to scan all 21,349 documents in the collection to find the 3,809 matching documents. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- - [`executionStats.totalDocsExamined`](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.totalDocsExamined) display `3809` to indicate that MongoDB scanned 3,809 documents. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md#mongodb-shell)
- executionStats.nReturned displays 3809 to indicate that the winning query plan returns 3,809 documents. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- | Parameter | Necessity | Type | Description | | --- | --- | --- | --- | | `verbose` | Optional | String | Determines the amount of information to include in the explain output. The possible verbosity modes are: `allPlansExecution`; `executionStats`; `queryPlanner` (*Default*) For backwards compatibility with earlier versions of `explain()`, MongoDB interprets `true` as `allPlansExecution` and `false` as `queryPlanner`. For more information on the modes, see [Verbosity Modes.](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#std-label-explain-cursor-method-verbosity) | — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- If you run `cursor.explain()` against a database that does not exist on a sharded cluster, the execution stage reaches the end-of-stream and the operation does not create the database. For more information on end-of-stream execution stats, see [`explain.executionStats.executionStages.isEOF`.](https://www.mongodb.com/docs/manual/reference/explain-results.md#mongodb-data-explain.executionStats.executionStages.isEOF) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#sharded-clusters)
- The following example runs [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) in ["executionStats"](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-executionStats) verbosity mode to return the query planning and execution information for the specified [`db.collection.find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#mongodb-method-db.collection.find) operation: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#example)
- The following query uses the `options` parameter to get the `executionStats` explain output: — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.find.md#explain-with-options)
- Counts of the types of plan stages that appear in the winning plans. A single winning plan can match multiple node counters. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- Counts the types of plan stages that appear in each winning plan. The node counters are not mutually exclusive, so one query execution can increment several of them. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- You can view more verbose explain output by passing the `executionStats` or `allPlansExecution` explain modes to the [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) method. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#return-information-on-aggregation-pipeline-operation)
- For more information on execution statistics of collection scans, see [Interpret Explain Plan Results.](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md) — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#collection-scan)
- explain.queryPlanner.winningPlan.inputStage — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.queryPlanner.winningPlan.inputStages — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.queryPlanner.winningPlan.queryPlan.inputStage — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- See explain.queryPlanner.winningPlan.inputStage. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The returned explain.executionStats information details the execution of the winning plan. To include executionStats in the results, you must run the explain in either: — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- allPlansExecution verbosity mode. Use allPlansExecution mode to include partial execution data captured during plan selection. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- For more information on execution statistics of collection scans, see Interpret Explain Plan Results. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Query knobs set through query settings always appear, even if their value equals the default. However, explain output omits query knobs that you have not explicitly set. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The default verbosity of `explain` and [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) differs. `explain` defaults to `allPlansExecution` while `db.collection.explain()` defaults to `queryPlanner`. — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#command-fields)
- Affects how thoroughly MongoDB indexes range values. Low sparsity (dense indexing) improves query performance, but stores more documents in the encrypted metadata collections for each insert or update operation, causing greater storage overhead. High sparsity does the opposite. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- ).hint( { year: 1, rated: 1 } ).explain("executionStats") — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- ).hint( { rated: 1, year: 1 } ).explain("executionStats") — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- The following example shows how MongoDB uses bounds intersection to define a smaller range of values to query, resulting in improved query performance. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- The following example shows how MongoDB uses compound bounds to define a more efficient query constraint, resulting in improved query performance. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- system.profile.keysExamined — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- system.profile.docsExamined — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- system.profile.execStats.inputStages — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- "planSummary" : "IXSCAN { a: 1, _id: -1 }", — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- You can also unsubscribe by clicking the unsubscribe link in any Query Shape Report email. The link directs you to Project Settings, where Atlas unsubscribes the project. The unsubscribe link works without requiring you to log in. — [source](https://www.mongodb.com/docs/atlas/query-shape-insights.md#manage-report-subscriptions)
- Before MongoDB 7.0.22, 8.0.5, and 8.1.0, `planningTimeMicros` might include work that the command performs before a query retry, such as a sharding metadata refresh. Don't rely on this field alone to evaluate query-planning performance. To evaluate query-planning performance, review the total operation duration, [`keysExamined`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.keysExamined), [`docsExamined`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.docsExamined), and relevant sharding or lock-wa — [source](https://www.mongodb.com/docs/manual/reference/database-profiler.md#output-fields)
- explain.executionStats.executionStages.inputStage — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Each stage passes its resulting documents or index keys to the parent node. The leaf nodes access the collection or the indices. The internal nodes use the documents or the index keys that result from the child nodes. The root node indicates the stage that MongoDB ultimately derives the result set from. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- - `EXPRESS` stages for a limited set of queries that can bypass regular query planning to use optimized index scan plans *(New in version 8.0.)* — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#classic-execution-engine)
- A document that describes the child stage, which provides the documents or index keys to its parent. The field is present *if* the parent stage has only one child. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- An array of documents describing the child stages. Child stages provide the documents or index keys to the parent stage. The field is present *if* the parent stage has multiple child nodes. For example, stages for [$or expressions](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-output-or-expression) might consume input from multiple sources. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Each knob keeps the type, bounds, and default of its underlying server parameter, and `setQuerySettings` runs the same validation that [`setParameter`](https://www.mongodb.com/docs/manual/reference/command/setparameter.md#mongodb-dbcommand-dbcmd.setParameter) runs. `setQuerySettings` rejects the following values: — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md#query-knobs)
- In general, if keysExamined is much higher than nreturned, the database is scanning many index keys to find the result documents. Consider creating or adjusting indexes to improve query performance.. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- - Bounded clustered collection scans that specify `min` and `max` record bounds — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#general-parameters)
- In previous versions of MongoDB, `cursor.explain()` returned the `clauses` array that detailed the indexes. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#or-expression)
- 2. Create a multikey index — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- - The bounds for the greater than or equal to 90 predicate (`$gte: 90`) are `[ [ 90, Infinity ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- - The bounds for the less than or equal to 99 predicate (`$lte: 99`) are `[ [ -Infinity, 99 ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-bounds-intersection)
- MongoDB makes no guarantee as to which of the two bounds it chooses. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#query-without-elemmatch)
- 2. Create a compound multikey index — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- The preceding query specifies a condition on both keys of the index (`item` and `ratings`). — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- - The bounds for the `item: "XYZ"` predicate are `[ [ "XYZ", "XYZ" ]]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- - The bounds for the `ratings: { $gte: 3 }` predicate are `[ [ 3, Infinity ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-array-field)
- - The bounds for the `item: "XYZ"` predicate are `[ [ "XYZ", "XYZ" ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- - The bounds for the `score: { $lte: 5 }` predicate are `[ [ -Infinity, 5] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- - The bounds for the `by: "anon"` predicate are `[ "anon", "anon" ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- - MongoDB compounds the `item` bounds with the `"ratings.score"` bounds: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- - MongoDB compounds the `item` bounds with the `"ratings.by"` bounds: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- - The index keys must share the same field path up to but excluding the field names. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#compound-bounds-of-multiple-fields-from-the-same-array)
- 1. Create a compound multikey index — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example)
- - The bounds for the `score: { $lte: 5 }` predicate are `[ [ -Infinity, 5 ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example)
- - The bounds for the `by: "anon"` predicate are `[ [ "anon", "anon" ] ]`. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example)
- If you use [`min()`](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#mongodb-method-cursor.min) with [`max()`](https://www.mongodb.com/docs/manual/reference/method/cursor.max.md#mongodb-method-cursor.max) to specify a range: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#index-bounds)
- - the bound specified by [`max()`](https://www.mongodb.com/docs/manual/reference/method/cursor.max.md#mongodb-method-cursor.max) must be greater than the bound specified by [`min()`.](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#mongodb-method-cursor.min) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#index-bounds)
- A string that specifies the [namespace](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-namespace) with the names of the database and the collection accessed by the query. The namespace has the format `<database>.<collection>`. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- Starting in MongoDB 8.0, if a query uses [block processing](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-querying.md#std-label-timeseries-querying-block-processing), `block_to_row` and `ts_bucket_to_cellblock` appear in the `stages` output. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- The explain execution statistics provide the peak memory for the entire query and also for each blocking stage. If there is only one blocking stage, the query and stage `peakTrackedMemBytes` values are the same. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- MongoDB 8.2 removes `profileOperationResourceConsumptionMetrics`. Therefore, code depending on [operationMetrics](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-executionStats) does not work. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#unsharded-collections)
- | Name | Notes | | --- | --- | | [MongoDB Cloud Manager](https://www.mongodb.com/products/tools/cloud-manager) | MongoDB Cloud Manager is a cloud-based suite of services for managing MongoDB deployments. MongoDB Cloud Manager provides monitoring, backup, and automation functionality. For an on-premises solution, see also [Ops Manager, available in MongoDB Enterprise Advanced.](https://www.mongodb.com/products/mongodb-enterprise-advanced) | | [VividCortex](https://www.vividcortex.com/) | VividCortex provides deep insights into MongoDB [production database workload and query performance](https:/ — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#hosted-saas-monitoring-tools)
- The `IXSCAN` also includes the specification document of the index used. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp.md#output-fields)
- For write operations, keysExamined and docsExamined include reads performed during write conflict retries. If an update encounters write conflicts and retries, MongoDB re-reads the index keys and documents on each attempt. As a result, these values can exceed the number of documents matched or modified by the operation. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- If $in has fewer than 201 array elements, the elements are expanded and then merged in the sort order specified for the index using a SORT_MERGE stage. This improves performance for small arrays. In this case, $in is similar to an equality predicate with ESR. — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-rule/)
- executionStats.totalKeysExamined displays 0 to indicate that this query is not using an index. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- MongoDB scanned 246 index keys (executionStats.totalKeysExamined) to return 235 matching documents (executionStats.nReturned). — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- The `trimFactor` controls the throughput of concurrent inserts and updates. A higher `trimFactor` increases the throughput of concurrent insert and updates at the cost of slowing down some range read operations. A lower `trimFactor` does the opposite. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- For more thorough information on contention factor and its cryptographic implications, see "Section 9: Guidelines" in MongoDB's [Queryable Encryption Technical Paper](https://www.mongodb.com/resources/products/capabilities/queryable-encryption-technical-paper). — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- - `timeField` values that are close together. The time series collection's `granularity`, `bucketMaxSpanSeconds`, and `bucketRoundingSeconds` parameters control the time span covered by each bucket. For more information, see [Set Granularity for Time Series Data.](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity) — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-bucketing-works)
- If a document with a time of `2023-03-27T16:24:35Z` does not fit an existing bucket, MongoDB creates a new bucket with a minimum time of `2023-03-27T16:00:00Z` and a maximum time of `2023-03-27T16:59:59Z`. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-bucketing-works)
- You can modify a time series collection's granularity, but only to change from finer to coarser measurements, such as extending bucket coverage from minutes to hours. This doesn't change how data is stored across existing buckets. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#how-bucketing-works)
- The following [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) command runs in `"queryPlanner"` verbosity mode to return the query planning information for a [`count`](https://www.mongodb.com/docs/manual/reference/command/count.md#mongodb-dbcommand-dbcmd.count) command: — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#queryplanner-mode)
- The indexes specified to indexNames must be the entire set of in-progress builds associated to a given index builder, i.e. the indexes built by a single createIndexes or db.collection.createIndexes() operation. — [source](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum/)
- The indexes specified to indexNames must be the entire set of in-progress builds associated to a given index builder, i.e. the createIndexes() operation. — [source](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum/)
- The indexNames field specifies the names of the indexes. Since the indexes were created without an explicit name, MongoDB generated an index name by concatenating the names of the indexed fields and the sort order. — [source](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum/)
- - Choose a field such as `_id` which generally changes in a consistent direction over time and has a [unique index](https://www.mongodb.com/docs/manual/core/index-unique.md#std-label-index-type-unique) to prevent duplicate values, — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.skip.md#descending-order)
- Specifies the index's fields. For each field, specify a key-value pair in which the key is the name of the field to index and the value is either the index direction or index type. If specifying direction, specify 1 for ascending or -1 for descending. — [source](https://www.mongodb.com/docs/manual/reference/command/createIndexes/)
- - To learn how MongoDB combines multikey index bounds to improve performance, see [Multikey Index Bounds.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-indexes-multikey-bounds) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey.md#learn-more)
- If an ascending or a descending index is on a single field, the sort operation on the field can be in either direction. — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)
- For a query to use a compound index for a sort, the specified sort direction for all keys in the cursor.sort() document must match the index key pattern or match the inverse of the index key pattern. For example, an index key pattern { a: 1, b: -1 } can support a sort on { a: 1, b: -1 } and { a: -1, b: 1 } but not on { a: -1, b: -1 } or {a: 1, b: 1}. — [source](https://www.mongodb.com/docs/manual/tutorial/sort-results-with-indexes/)
- ```javascript db.runCommand( { collMod: "apples", index: { keyPattern: { type: 1 }, prepareUnique: true } } ) ``` — [source](https://www.mongodb.com/docs/manual/core/index-unique/convert-to-unique.md#steps)
- ```javascript db.runCommand( { collMod: "apples", index: { keyPattern: { type: 1 }, unique: true }, dryRun: true } ) ``` — [source](https://www.mongodb.com/docs/manual/core/index-unique/convert-to-unique.md#steps)
- ```javascript db.runCommand( { collMod: "apples", index: { keyPattern: { type: 1 }, unique: true } } ) ``` — [source](https://www.mongodb.com/docs/manual/core/index-unique/convert-to-unique.md#steps)
- db.pizzaOrders.explain().find( — [source](https://www.mongodb.com/docs/manual/core/query-shapes/)
- MongoDB combines bounds by either [intersecting](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-multikey-index-bounds-intersecting) or [compounding](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-multikey-index-bounds-compound) bounds. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md)
- Given an indexed array field, consider a query that specifies multiple query predicates on the array and uses a [multikey index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey.md#std-label-index-type-multikey) to fulfill the query. MongoDB can intersect the multikey index bounds if an [`$elemMatch`](https://www.mongodb.com/docs/manual/reference/operator/query/elemmatch.md#mongodb-query-op.-elemMatch) operator joins the query predicates. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#bounds-intersection-for-a-multikey-index)
- For example, consider a compound index `{ temperature: 1, humidity: 1 }` with the following bounds: — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#compound-bounds-for-a-multikey-index)
- MongoDB compounds the bounds for the `item` key with either the bounds for `"ratings.score"` or the bounds for `"ratings.by"`, depending upon the query predicates and the index key values. MongoDB does not guarantee which bounds it compounds with the `item` field. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example-compound-bounds-of-non-array-field-and-multiple-array-fields)
- For a field in an embedded document, the [dotted field name](https://www.mongodb.com/docs/manual/core/document.md#std-label-document-dot-notation), such as `"a.b.c.d"`, is the field path for `d`. To compound the bounds for index keys from the same array, the `$elemMatch` must be on the path up to *but excluding* the field name itself (meaning `"a.b.c"`). — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#compound-bounds-of-multiple-fields-from-the-same-array)
- The following example shows how MongoDB combines bounds for index keys from the same array. This example uses the `survey2` collection used in the [previous example.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-index-bounds-example-non-array-multiple-array) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#example)
- In the top right of the aggregation pipeline builder, click the Explain button to open the Explain Plan modal. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline-builder/view-pipeline-explain-plan.md#steps)
- | Parameter | Type | Description | | --- | --- | --- | | `indexBounds` | document | The inclusive lower bound for the index keys. | — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#definition)
- - the index bounds specified in [`min()`](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#mongodb-method-cursor.min) and [`max()`](https://www.mongodb.com/docs/manual/reference/method/cursor.max.md#mongodb-method-cursor.max) must both refer to the keys of the same index. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#index-bounds)
- Indexes store entries in either ascending (`1`) or descending (`-1`) order. For [compound indexes](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md#std-label-index-type-compound), sort order can determine whether the index can support a sort operation. The direction of a field in a compound index is relevant only if there is a sort on multiple fields in opposite directions. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound/sort-order.md)
- MongoDB can traverse a compound index in either direction. If the application allows users to view the leaderboard in reverse order, the index supports that query as well. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound/sort-order.md#reverse-results)
- | Name | Type | Required | Description | | --- | --- | --- | --- | | indexName | string | false | Name of the index. | — [source](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-create.md#arguments)
- On the Explain Plan modal, you can view the explain stages as a Visual Tree, where each query operation appears as a node on the tree. You can also view the explain details in raw JSON format by selecting the Raw Output view. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/query-plan.md#about-this-task)
- For example, the following explain plan provides detailed information on a query that filters for `{ title : "Jurassic Park" }`: — [source](https://www.mongodb.com/docs/atlas/atlas-ui/query-plan.md#steps)
- The default location bounds for 2d indexes allow latitudes less than -90 and greater than 90, which are invalid values. The behavior of geospatial queries with these invalid points is not defined. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2d/create/define-location-range.md#about-this-task)
- Explain plan results for queries are subject to change between MongoDB versions. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan.md)
- You can see the optimized pipeline in the [explain plan.](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#std-label-example-aggregate-method-explain-option) — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#project-or-unset-or-addfields-or-set-match-sequence-optimization)
- You can see this optimized pipeline in the [explain plan.](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#std-label-example-aggregate-method-explain-option) — [source](https://www.mongodb.com/docs/manual/core/aggregation-pipeline-optimization.md#lookup-unwind-and-match-coalescence)
- The `explain()` method has the following form: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- The `explain()` method has the following parameter: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#definition)
- The behavior of [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) and the amount of information returned depend on the `verbosity` mode. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#verbosity-modes)
- [`db.collection.explain().find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) is similar to [`db.collection.find().explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) with the following key differences: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#db-collection-explain-find)
- - The [`db.collection.explain().find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) construct allows for the additional chaining of query modifiers. For list of query modifiers, see [db.collection.explain().find().help().](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-help) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#db-collection-explain-find)
- [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) operations can return information regarding: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- - [`serverInfo`](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-serverInfo), which provides information on the MongoDB instance. — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#output)
- For more examples, see [Examples](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-examples). See also [db.collection.explain().help().](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-method-help) — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#description)
- The [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) method has the following parameter: — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#parameters)
- For write operations, [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) returns information about the write operation that would be performed but does not actually modify the database. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#explain-and-write-operations)
- The [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) method wraps the [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) command and is the preferred way to run [`explain`.](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#explain-mechanics)
- [`db.collection.explain().aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) is equivalent to passing the [explain](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#std-label-example-aggregate-method-explain-option) option to the [`db.collection.aggregate()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#mongodb-method-db.collection.aggregate) method. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#explain-mechanics)
- [`db.collection.explain().find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) returns a cursor, which allows for the chaining of query modifiers. To see the list of query modifiers supported by [`db.collection.explain().find()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) as well as cursor-related methods, run: — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#help)
- You can chain multiple modifiers to `db.collection.explain().find()`. For an example, see [Explain `find()` with Modifiers.](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#std-label-explain-find-modifiers) — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#help)
- - To learn about multikey index bounds, see [Multikey Index Bounds.](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/multikey-index-bounds.md#std-label-indexes-multikey-bounds) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-multikey/create-multikey-index-basic.md#learn-more)
- ```javascript { cursor: { id: Long('0'), ns: 'test.$cmd.aggregate', firstBatch: [ { type: 'InconsistentIndex', description: 'Found an index of a sharded collection that is inconsistent between different shards', details: { namespace: 'test.reviews', info: { missingFromShards: [], inconsistentProperties: [ { k: 'expireAfterSeconds', v: Long('600') }, { k: 'expireAfterSeconds', v: 3600 } ], indexName: 'reviewDt_1' } } }, { type: 'InconsistentIndex', description: 'Found an index of a sharded collection that is inconsistent between different shards', details: { namespace: 'test.reviews', info: { m — [source](https://www.mongodb.com/docs/manual/tutorial/manage-indexes.md#find-inconsistent-indexes-across-shards)
- - The [cursor.explain()](https://www.mongodb.com/docs/manual/reference/method/cursor.explain/) command for [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) provides performance details for all queries. — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting.md#fix-the-immediate-problem)
- Index scans where a field has multiple bounds, counted separately by the number of bounds. boundsUnionedSmall counts fields with 2 to 50 bounds, and boundsUnionedLarge counts fields with 51 or more bounds. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- The following example uses [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) to view detailed information regarding the execution plan of the aggregation pipeline. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.aggregate.md#return-information-on-aggregation-pipeline-operation)
- **Note: The explain output is subject to change between releases.** — [source](https://www.mongodb.com/docs/manual/reference/command/aggregate.md#return-information-on-the-aggregation-operation)
- This section shows the `explain` output for MongoDB 5.1 and later. To see the explain output for older versions of MongoDB, refer to the documentation for that version. — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#explain-output-for-mongodb-5-1-and-later)
- The [explain results](https://www.mongodb.com/docs/manual/reference/explain-results.md#std-label-explain-results) can include execution statistics for queries that use a [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) pipeline stage. To include those execution statistics, you must run the explain operation in one of these execution verbosity modes: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#execution-plan-statistics-for-query-with-lookup-pipeline-stage)
- The following fields are included in the explain results for a [`$lookup`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup.md#mongodb-pipeline-pipe.-lookup) query: — [source](https://www.mongodb.com/docs/manual/reference/explain-results.md#execution-plan-statistics-for-query-with-lookup-pipeline-stage)
- Unique integer field that identifies each stage in the execution plan. Field is included in all stages throughout the explain results. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The explain results can include execution statistics for queries that use a $lookup pipeline stage. To include those execution statistics, you must run the explain operation in one of these execution verbosity modes: — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The explain results includes execution statistics for queries that use a $search, $searchMeta, or $vectorSearch pipeline stage. To include execution statistics for search queries, run the explain command in one of the following execution verbosity modes: — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Starting in MongoDB 8.0, explain outputs the following field: — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Starting in MongoDB 9.0, explain outputs the following field: — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- The cursor.explain() command for mongosh provides performance details for all queries. — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting/)
- In [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#std-program-mongosh), this command can also be run through the [`db.collection.explain()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#mongodb-method-db.collection.explain) and [`cursor.explain()`](https://www.mongodb.com/docs/manual/reference/method/cursor.explain.md#mongodb-method-cursor.explain) helper methods. — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#definition)
- - The indexes specified to `indexNames` must be the entire set of in-progress builds associated to a given index builder, i.e. the [`createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes) operation. — [source](https://www.mongodb.com/docs/manual/reference/command/setIndexCommitQuorum.md#examples)
- | Product Name | Minimum Version | Supports Queryable Encryption with Automatic Encryption | Supports Queryable Encryption with Explicit Encryption | | --- | --- | --- | --- | | MongoDB Atlas | 7.0 | Yes | Yes | | MongoDB Enterprise Advanced | 7.0 | Yes | Yes | | MongoDB Community Edition | 7.0 | No | Yes | — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/compatibility.md#mongodb-compatibility)
- | Product Name | Minimum Version | Supports CSFLE with Automatic Encryption | Supports CSFLE with Explicit Encryption | | --- | --- | --- | --- | | MongoDB Atlas | [All supported MongoDB versions](https://www.mongodb.com/docs/atlas/reference/faq/database/#which-versions-of-mongodb-do-service-clusters-use-) | Yes | Yes | | MongoDB Enterprise Advanced | 4.2 | Yes | Yes | | MongoDB Community Edition | 4.2 | No | Yes | — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/reference/compatibility.md#mongodb-compatibility)
- These parameters are intended for advanced users only. The default values are suitable for the majority of use cases, and should only be modified if your use case requires it. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#advanced-query-parameters)
- Only appears if usedDisk is true. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- Don't rely on this field alone to evaluate query-planning performance. Review the total operation duration, keysExamined, docsExamined, and relevant sharding or lock-wait metrics. — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- "executionTimeMillisEstimate" : 0, — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- "executionTimeMillisEstimate" : 103771, — [source](https://www.mongodb.com/docs/manual/reference/database-profiler/)
- 2. Add a sort stage to sort by order date. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/group-and-total.md#steps)
- 4. Add a sort stage to sort by first order date. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/group-and-total.md#steps)
- 2) Add a sort stage to sort by order date. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/group-and-total.md#steps)
- 4) Add a sort stage to sort by first order date. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/group-and-total.md#steps)
- The maximum amount by which the current cluster time can be advanced; specifically, [`maxAcceptableLogicalClockDriftSecs`](https://www.mongodb.com/docs/manual/reference/parameters.md#mongodb-parameter-param.maxAcceptableLogicalClockDriftSecs) is the maximum difference between the new value of the cluster time and the current cluster time. Cluster time is a logical time used for ordering of operations. — [source](https://www.mongodb.com/docs/manual/reference/parameters.md#replication-and-consistency)
- On this page, you can learn about the security benefits of Queryable Encryption, how it works, and how it compares to other security mechanisms supported by MongoDB. You can also view a fictional scenario that demonstrates the value of Queryable Encryption in securing your data. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#overview)
- | Threat | TLS/SSL Transport Encryption | Encryption at Rest (EaR) | Queryable Encryption + TLS/SSL + EaR | CSFLE + TLS/SSL + EaR | | --- | --- | --- | --- | --- | | Network Snooping (attacker has access to network traffic) | Reveals [operation metadata](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-operation-metadata) | Reveals operation metadata | Reveals operation metadata | Reveals operation metadata | | Database Recoveries from Disk (attacker has physical disk access) | Reveals database | Reveals *size of database* and operation metadata | Reveals *size of database* a — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/features.md#comparison-of-features)
- ).explain("executionStats") — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- totalDocsExamined: 21349, — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- executionStats.totalDocsExamined display 3809 to indicate that MongoDB scanned 3,809 documents. — [source](https://www.mongodb.com/docs/manual/tutorial/analyze-query-plan/)
- All metrics in this document are reported on both [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) and [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos). On [`mongos`](https://www.mongodb.com/docs/manual/reference/program/mongos.md#mongodb-binary-bin.mongos), the `docsExamined` and `bytesRead` counters are aggregated from the shards that serve the change stream. The remaining metrics aren't aggregated from shards and count only the change stream cursors that the [`mongos`](https://www.mongo — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- A document that holds counters related to sort stages. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- The total number of writes to disk caused by sort stages. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- Aggregates the total number of "works" performed in the classic multiplanner. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- A histogram measuring the number of "works" performed during an invocation of the classic multiplanner. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- - The sync source's majority commit point has advanced since the last batch sent to this secondary. — [source](https://www.mongodb.com/docs/manual/reference/command/serverStatus.md#metrics)
- | Mode | Description | | --- | --- | | `AES256-CBC` | 256-bit Advanced Encryption Standard in Cipher Block Chaining Mode | | `AES256-GCM` | 256-bit Advanced Encryption Standard in Galois/Counter Mode Available only on Linux. MongoDB Enterprise on Windows no longer supports `AES256-GCM` as a block cipher for encryption at rest. This usage is only supported on Linux. | — [source](https://www.mongodb.com/docs/manual/reference/program/mongod.md#encryption-key-management-options)
- Available tabs: other tabs: queryplanner, executionstats, allplans --> — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md)
- - run the explain in `executionStats` mode or `allPlansExecution` mode but without the [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) stage to return information for the stages that precede the [`$out`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out.md#mongodb-pipeline-pipe.-out) stage. — [source](https://www.mongodb.com/docs/manual/reference/method/db.collection.explain.md#restrictions)
- - MongoDB Ops Manager is [an on-premises solution available in MongoDB Enterprise Advanced](https://www.mongodb.com/products/mongodb-enterprise-advanced) that monitors running MongoDB deployments to collect data and provide visualization and alerts based on that data. — [source](https://www.mongodb.com/docs/manual/administration/monitoring.md#monitoring-strategies)
- - Use [MongoDB Cloud Manager](https://www.mongodb.com/products/tools/cloud-manager) or [Ops Manager, an on-premise solution available in MongoDB Enterprise Advanced](https://www.mongodb.com/products/mongodb-enterprise-advanced) or another monitoring system to monitor key database metrics and set up alerts for them. Include alerts for the following metrics: — [source](https://www.mongodb.com/docs/manual/administration/production-checklist-operations.md#monitoring)
- Fetch stages, counted separately based on whether the stage applies a filter. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- usedDisk: {true: Long("0"), false: Long("1")}, — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/)
- ```python find_payload = client_encryption.encrypt( patientId, Algorithm.INDEXED, data_key_id_1, query_type=QueryType.EQUALITY, contention_factor=8, ) doc = coll.find_one({"encryptedIndexed": find_payload}) print("\nReturned document:\n") pprint.pprint(doc) ``` — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/tutorials/explicit-encryption.md#procedure)
- If the query bar is empty, you can click the filter bar to open the query autocomplete menu and view up to 50 recent or favorite queries. To scroll through your most recent queries, you can use the up ↑ and down ↓ arrow keys. If a query is highlighted on the menu, it displays a pop-up panel that shows the filter, project, and sort stages of the query. To select a query from the autocomplete menu, press Enter, press Tab, or click the query. — [source](https://www.mongodb.com/docs/atlas/atlas-ui/query/recent.md#query-autocomplete-menu)
- 2) Add a sort stage to sort from youngest to oldest. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/filtered-subset.md#steps)
- 2. Add a sort stage to sort from youngest to oldest. — [source](https://www.mongodb.com/docs/manual/tutorial/aggregation-examples/filtered-subset.md#steps)
- <executionPart>SpilledRecords indicates the number of records written to temporary files on disk. — [source](https://www.mongodb.com/docs/manual/reference/log-messages/)
- For more information on how sharding works with aggregations, read the sharding chapter in the Practical MongoDB Aggregations e-book. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router/)
- executionTimeMillis: <int>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- totalKeysExamined: <int>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- totalDocsExamined: <int>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- executionTimeMillisEstimate: <int>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- spilledRecords: <long long>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.nReturned — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionTimeMillis — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.peakTrackedMemBytes — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.totalKeysExamined — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.totalDocsExamined — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.score — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.executionTimeMillisEstimate — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.opens — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.closes — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.works — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.saveState — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.restoreState — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.isEOF — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.opType — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.bucketFilter — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.residualFilter — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nBucketsUnpacked — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nMeasurementsDeleted — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nMeasurementsInserted — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nMeasurementsMatched — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nMeasurementsModified — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.executionStages.nMeasurementsUpserted — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- Starting in MongoDB 9.0, the COUNT_SCAN, GEO_NEAR_2D, GEO_NEAR_2DSPHERE, and UPDATE stages also report this field. — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- COUNT_SCAN, GEO_NEAR_2D, GEO_NEAR_2DSPHERE, GROUP, SORT, UPDATE — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.allPlansExecution — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionStats.operationMetrics — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- totalDocsExamined: <long>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- totalKeysExamined: <long>, — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- executionTimeMillisEstimate: <long> — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.totalDocsExamined — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.totalKeysExamined — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- explain.executionTimeMillisEstimate — [source](https://www.mongodb.com/docs/manual/reference/explain-results/)
- docsExamined: 10000 cursorExhausted:1 numYields:234 — [source](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/query-targeting/)
- For more information on how sharding works with [aggregations](https://www.mongodb.com/docs/manual/core/aggregation-pipeline.md#std-label-aggregation-pipeline), read the sharding chapter in the [Practical MongoDB Aggregations](https://www.practical-mongodb-aggregations.com/guides/sharding.html) e-book. — [source](https://www.mongodb.com/docs/manual/core/sharded-cluster-query-router.md#using-aggregation-pipelines-with-clusters)
- The following [`explain`](https://www.mongodb.com/docs/manual/reference/command/explain.md#mongodb-dbcommand-dbcmd.explain) operation runs in `"executionStats"` verbosity mode to return the query planning and execution information for a [`count`](https://www.mongodb.com/docs/manual/reference/command/count.md#mongodb-dbcommand-dbcmd.count) command: — [source](https://www.mongodb.com/docs/manual/reference/command/explain.md#executionstats-mode)
- indexNames: [ <document> ], — [source](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum/)
- "indexNames" : ["invoices_1", "fullfillmentStatus_1"], — [source](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum/)
- - [`$densify`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#mongodb-pipeline-pipe.-densify) does not filter out documents with [field](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#std-label-densify-field) values outside of the specified bounds. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#range-bounds-behavior)
- Starting in MongoDB 8.0, [`$densify`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#mongodb-pipeline-pipe.-densify) treats bounds with an equal lower and upper bound as an empty set and does not generate a document with the bound as the field value. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#range-bounds-behavior)
- For example, a [range.bounds](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#std-label-densify-bounds) of `[10, 10]` generates an extra document with field value `10` in versions prior to 8.0, but does not generate such a document in 8.0 and later. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#range-bounds-behavior)
- - `bounds: [ ISODate("2021-05-18T00:00:00.000Z"), ISODate("2021-05-18T08:00:00.000Z") ]` sets the range of time that is densified. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify.md#densify-time-series-data)
- - For encrypted fields with range queries enabled, review the field configuration, especially the [min, max,](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#std-label-qe-field-min-max) and [precision](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query.md#std-label-qe-field-precision) parameters. Setting tight bounds for range queries greatly decreases the performance impact of those fields. — [source](https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/manage-collections.md#best-practices)
- - Time has moved forward or backward past the covered time span, as indicated by an incoming document timestamp that falls outside of the bucket's bounds. These bounds are determined by the collection's [granularity](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity.md#std-label-timeseries-granularity) setting. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing.md#closure)
- Follow the directions on the [.NET/C# Driver Get Started](https://www.mongodb.com/docs/drivers/csharp/current/get-started/) page to create a new project and install driver dependencies. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- Follow the directions on the [Java Sync Driver Get Started](https://www.mongodb.com/docs/drivers/java/sync/current/get-started/) page to create a new project and install driver dependencies. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- Follow the directions on the [Node.js Get Started](https://www.mongodb.com/docs/drivers/node/current/get-started/) page to create a new project directory and install driver dependencies. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- Follow the directions on the [PyMongo Get Started](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/get-started/) page to create a new project directory and install driver dependencies. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-quick-start.md)
- ```json { "ts" : { "$date" : "1984-03-05T13:00:00Z" }, "metaData" : { "callLetters" : "VCSZ", "elevation" : 9999, "position" : { "coordinates" : [ -47.9, 47.6 ], "type" : "Point" }, "qualityControlProcess" : "V020", "st" : "x+47600-047900", "type" : "FM-13" }, "dewPoint" : { "value" : 999.9, "quality" : "9" }, "wind" : { "direction" : { "angle" : 999, "quality" : "9" }, "type" : "9", "speed" : { "rate" : 999.9, "quality" : "9" } }, "skyCondition" : { "ceilingHeight" : { "value" : 99999, "quality" : "9", "determination" : "9" }, "cavok" : "N" }, "dataSource" : "4", "pressure" : { "value" : 1015 — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- ```text { "_id": {"$oid": "<object-id>"}, "ts": {"$date": "1984-03-05T13:00:00Z"}, "metaData": { "st": "x+47600-047900", "position": {"type": "Point", "coordinates": [-47.9, 47.6]}, "elevation": 9999, "callLetters": "VCSZ", "qualityControlProcess": "V020", "type": "FM-13" }, "dataSource": "4", "airTemperature": {"value": -3.1, "quality": "1"}, "dewPoint": {"value": 999.9, "quality": "9"}, "pressure": {"value": 1015.3, "quality": "1"}, "wind": { "direction": {"angle": 999, "quality": "9"}, "type": "9", "speed": {"rate": 999.9, "quality": "9"} }, "visibility": { "distance": {"value" — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- ```shell { _id: ObjectId("<object-id>"), ts: ISODate("1984-03-05T13:00:00Z"), metaData: { st: "x+47600-047900", position: { type: "Point", coordinates: [ -47.9, 47.6 ] }, elevation: 9999, callLetters: "VCSZ", qualityControlProcess: "V020", type: "FM-13" }, dataSource: "4", airTemperature: { value: -3.1, quality: "1" }, dewPoint: { value: 999.9, quality: "9" }, pressure: { value: 1015.3, quality: "1" }, wind: { direction: { angle: 999, quality: "9" }, type: "9", speed: { rate: 999.9, quality: "9" } }, visibility: { distance: { value: 999999, quality: "9" }, variability: { value: "N — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- ```text { _id: new ObjectId('<object-id>'), ts: 1984-03-05T13:00:00.000Z, metaData: { st: 'x+47600-047900', position: { type: 'Point', coordinates: [ -47.9, 47.6 ] }, elevation: 9999, callLetters: 'VCSZ', qualityControlProcess: 'V020', type: 'FM-13' }, dataSource: '4', airTemperature: { value: -3.1, quality: '1' }, dewPoint: { value: 999.9, quality: '9' }, pressure: { value: 1015.3, quality: '1' }, wind: { direction: { angle: 999, quality: '9' }, type: '9', speed: { rate: 999.9, quality: '9' } }, visibility: { distance: { value: 999999, quality: '9' }, variability: { value: 'N', q — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- ```text {'_id': ObjectId('<object-id>'), 'ts': datetime.datetime(1984, 3, 5, 13, 0), 'metaData': {'st': 'x+47600-047900', 'position': {'type': 'Point', 'coordinates': [-47.9, 47.6]}, 'elevation': 9999, 'callLetters': 'VCSZ', 'qualityControlProcess': 'V020', 'type': 'FM-13'}, 'dataSource': '4', 'airTemperature': {'value': -3.1, 'quality': '1'}, 'dewPoint': {'value': 999.9, 'quality': '9'}, 'pressure': {'value': 1015.3, 'quality': '1'}, 'wind': {'direction': {'angle': 999, 'quality': '9'}, 'type': '9', 'speed': {'rate': 999.9, 'quality': '9'}}, 'visibility': {'distance': {'value': 9 — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-aggregation.md#steps)
- "keyPattern": <keyPattern>, — [source](https://www.mongodb.com/docs/manual/core/index-ttl/)
- "keyPattern": { "lastModifiedDate": 1 }, — [source](https://www.mongodb.com/docs/manual/core/index-ttl/)
- ```javascript db.temporarytimeseries.findOne() { "_id" : ObjectId("<object-id>"), "ts" : ISODate("1984-03-05T13:00:00Z"), "dataSource" : "4", "airTemperature" : { "value" : -3.1, "quality" : "1" }, "dewPoint" : { "value" : 999.9, "quality" : "9" }, "pressure" : { "value" : 1015.3, "quality" : "1" }, "wind" : { "direction" : { "angle" : 999, "quality" : "9" }, "type" : "9", "speed" : { "rate" : 999.9, "quality" : "9" } }, "visibility" : { "distance" : { "value" : 999999, "quality" : "9" }, "variability" : { "value" : "N", "quality" : "9" } }, "skyCondition" : { "ceilingHeight" : { — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-with-tools.md#steps)
- If the array elements are documents, you can sort by a document field. Specify the field name and a sort direction, ascending (`1`), or descending (`-1` ). — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray.md#sort-by-document-fields)
- Returns the cosine similarity between two numeric vectors represented as arrays or `binData` values. Cosine similarity measures the cosine of the angle between two vectors and indicates how similar their directions are, independent of their magnitudes. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine.md#definition)
- - `1` indicates the vectors point in identical directions. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine.md#return-value)
- - `-1` indicates the vectors point in opposite directions. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine.md#return-value)
- The `indexBounds` parameter has the following prototype form: — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.min.md#definition)
- Specifies a polygon for a [geospatial](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-geospatial) [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geowithin.md#mongodb-query-op.-geoWithin) query on legacy coordinate pairs. The query returns pairs that are within the bounds of the polygon. The operator does *not* query for GeoJSON objects. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/polygon.md#definition)
- The `min` and `max` bounds are **inclusive** and apply to both longitude and latitude. — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/geospatial/2d/create/define-location-range.md)
- The [`$center`](https://www.mongodb.com/docs/manual/reference/operator/query/center.md#mongodb-query-op.-center) operator specifies a circle for a [`$geoWithin`](https://www.mongodb.com/docs/manual/reference/operator/query/geowithin.md#mongodb-query-op.-geoWithin) query. The query returns legacy coordinate pairs that are within the bounds of the circle. The operator does *not* return GeoJSON objects. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/center.md#definition)
- Defines a circle for a [geospatial](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-geospatial) query that uses spherical geometry. The query returns documents that are within the bounds of the circle. You can use the [`$centerSphere`](https://www.mongodb.com/docs/manual/reference/operator/query/centersphere.md#mongodb-query-op.-centerSphere) operator on both [GeoJSON](https://www.mongodb.com/docs/manual/reference/glossary.md#std-term-GeoJSON) objects and legacy coordinate pairs. — [source](https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere.md#definition)
- - An `_id` object that specifies the bounds of the bucket. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto.md#definition)
- Time has moved forward or backward past the covered time span, as indicated by an incoming document timestamp that falls outside of the bucket's bounds. These bounds are determined by the collection's granularity setting. — [source](https://www.mongodb.com/docs/manual/core/timeseries/timeseries-bucketing/)
- - If `idx` exceeds the array bounds, [`$arrayElemAt`](https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayelemat.md#mongodb-expression-exp.-arrayElemAt) does not return a result. — [source](https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt.md#behavior)

## Related concepts

- executionStats — is a part of MongoDB explain output and plan stages
- index — is a hypernym of MongoDB explain output and plan stages
- index bounds — is a related of MongoDB explain output and plan stages
- plan stage — is a part of MongoDB explain output and plan stages
- query planner — is a synonym of MongoDB explain output and plan stages
- database profiler — is a part of MongoDB explain output and plan stages
- query shape — is a part of MongoDB explain output and plan stages
- plan cache — is a part of MongoDB explain output and plan stages
- query optimization — is a hypernym of MongoDB explain output and plan stages
- hint — is a part of MongoDB explain output and plan stages
- query settings — is a part of MongoDB explain output and plan stages
- slot-based execution engine — is a related of MongoDB explain output and plan stages
- index effectiveness — is a measure of MongoDB explain output and plan stages
- $currentOp — is a related of MongoDB explain output and plan stages
- $indexStats — is a part of MongoDB explain output and plan stages
