- Reference >
- Explain Output
Explain Output¶
On this page
This document explains the output of the $explain
operator
and the mongo
shell method explain()
.
Explain Output¶
The Core Explain Output fields display information for
queries on non-sharded collections. For queries on sharded collections,
explain()
returns this information for each
shard the query accesses.
$or
Queries¶
Queries with $or
operator execute each clause of the
$or
expression in parallel and can use separate indexes on
the individual clauses. If the query uses indexes on any or all of the
query’s clause, explain()
contains
output for each clause as well as
the cumulative data for the entire query:
Sharded Collections¶
For queries on a sharded collection, the output contains the Core Explain Output for each accessed shard and cumulative shard information:
Fields¶
Core Explain Output¶
-
explain.
cursor
¶ cursor
is a string that reports the type of cursor used by the query operation:BasicCursor
indicates a full collection scan.BtreeCursor
indicates that the query used an index. The cursor includes name of the index. When a query uses an index, the output ofexplain()
includesindexBounds
details.GeoSearchCursor
indicates that the query used a geospatial index.
-
explain.
isMultiKey
¶ isMultiKey
is a boolean. Whentrue
, the query uses a multikey index, where one of the fields in the index holds an array.
-
explain.
n
¶ n
is a number that reflects the number of documents that match the query selection criteria.
-
explain.
nscannedObjects
¶ Specifies the total number of documents scanned during the query. The
nscannedObjects
may be lower thannscanned
, such as if the index covers a query. SeeindexOnly
. Additionally, thenscannedObjects
may be lower thannscanned
in the case of multikey index on an array field with duplicate documents.
-
explain.
nscanned
¶ Specifies the total number of documents or index entries scanned during the database operation. You want
n
andnscanned
to be close in value as possible. Thenscanned
value may be higher than thenscannedObjects
value, such as if the index covers a query. SeeindexOnly
.
-
explain.
nscannedObjectsAllPlans
¶ New in version 2.2.
nscannedObjectsAllPlans
is a number that reflects the total number of documents scanned for all query plans during the database operation.
-
explain.
nscannedAllPlans
¶ New in version 2.2.
nscannedAllPlans
is a number that reflects the total number of documents or index entries scanned for all query plans during the database operation.
-
explain.
scanAndOrder
¶ scanAndOrder
is a boolean that istrue
when the query cannot use the index for returning sorted results.When
true
, MongoDB must sort the documents after it retrieves them from either an index cursor or a cursor that scans the entire collection.
-
explain.
indexOnly
¶ indexOnly
is a boolean value that returnstrue
when the the query is covered by the index indicated in thecursor
field. When an index covers a query, MongoDB can both match the query conditions and return the results using only the index because:- all the fields in the query are part of that index, and
- all the fields returned in the results set are in the same index.
-
explain.
nYields
¶ nYields
is a number that reflects the number of times this query yielded the read lock to allow waiting writes execute.
-
explain.
nChunkSkips
¶ nChunkSkips
is a number that reflects the number of documents skipped because of active chunk migrations in a sharded system. Typically this will be zero. A number greater than zero is ok, but indicates a little bit of inefficiency.
-
explain.
indexBounds
¶ indexBounds
is a document that contains the lower and upper index key bounds. This field resembles one of the following:
-
explain.
allPlans
¶ allPlans
is an array that holds the list of plans the query optimizer runs in order to select the index for the query. Displays only when the<verbose>
parameter toexplain()
istrue
or1
.
$or
Query Output¶
Sharded Collections Output¶
-
explain.
clusteredType
¶ clusteredType
is a string that reports the access pattern for shards. The value is:
-
explain.
shards
¶ shards
is a document value that contains the shards accessed during the query and individual Core Explain Output for each shard.
-
explain.
millisShardTotal
¶ millisShardTotal
is a number that reports the total time in milliseconds for the query to run on the shards.
-
explain.
millisShardAvg
¶ millisShardAvg
is a number that reports the average time in millisecond for the query to run on each shard.
-
explain.
numQueries
¶ numQueries
is a number that reports the total number of queries executed.