-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcursor.explain.txt
153 lines (99 loc) · 3.69 KB
/
cursor.explain.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
================
cursor.explain()
================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. method:: cursor.explain(verbosity)
.. include:: /includes/fact-mongosh-shell-method.rst
Provides information on the query plan for the
:method:`db.collection.find()` method.
The ``explain()`` method has the following form:
.. code-block:: javascript
db.collection.find().explain()
The ``explain()`` method has the following parameter:
.. list-table::
:header-rows: 1
:widths: 20 10 10 80
* - 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
:ref:`explain-cursor-method-verbosity`.
The :method:`~cursor.explain()` method returns a document with the
query plan and, optionally, the execution statistics.
Compatibility
-------------
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
.. include:: /includes/fact-environments-onprem-only.rst
Required Access
---------------
.. include:: /includes/explain-required-access.rst
Behavior
--------
.. include:: includes/explain-ignores-cache-plan.rst
.. _explain-cursor-method-verbosity:
Verbosity Modes
~~~~~~~~~~~~~~~
The behavior of :method:`cursor.explain()` and the amount of
information returned depend on the ``verbosity`` mode.
.. |explain| replace:: :method:`cursor.explain()`
.. |operation| replace:: method
.. _explain-cursor-method-queryPlanner:
``queryPlanner`` Mode
``````````````````````
By default, :method:`cursor.explain()` runs in ``queryPlanner``
verbosity mode.
.. include:: /includes/fact-explain-verbosity-queryPlanner.rst
.. _explain-cursor-method-executionStats:
``executionStats`` Mode
```````````````````````
.. include:: /includes/fact-explain-verbosity-executionStats.rst
:end-before: start-explain-write
.. include:: /includes/fact-explain-verbosity-executionStats.rst
:start-after: end-explain-write
.. _explain-cursor-method-allPlansExecution:
``allPlansExecution`` Mode
``````````````````````````
.. include:: /includes/fact-explain-verbosity-allPlansExecution.rst
:end-before: start-explain-write
.. include:: /includes/fact-explain-verbosity-allPlansExecution.rst
:start-after: end-explain-write
``db.collection.explain().find()``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/fact-explain-methods-differences.rst
See :method:`db.collection.explain()` for more information.
.. _explain-cursor-method-output:
Output
------
.. include:: /includes/fact-explain-results-categories.rst
For details on the output, see :doc:`/reference/explain-results`.
Example
-------
The following example runs :method:`cursor.explain()` in
:ref:`"executionStats" <explain-method-executionStats>` verbosity mode
to return the query planning and execution information for the
specified :method:`db.collection.find()` operation:
.. code-block:: javascript
db.products.find(
{ quantity: { $gt: 50 }, category: "apparel" }
).explain("executionStats")