Skip to content

DOCS-14045 documents new explain fields #5334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions source/includes/fact-explain-results-categories.rst
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
|explain| operations can return information regarding:

- ``explainVersion``, the output format version (for example, ``"1"``);

- ``command``, which details the command being explained;

- :ref:`queryPlanner`, which details the plan selected by the
:doc:`query optimizer </core/query-plans>` and lists the rejected
plans;

- :ref:`executionStats`, which details the execution of the winning
plan and the rejected plans; and
plan and the rejected plans;

- :ref:`serverInfo`, which provides information on the
MongoDB instance.
MongoDB instance; and

- ``serverParameters``, which details internal parameters.

The verbosity mode (i.e. ``queryPlanner``, ``executionStats``,
``allPlansExecution``) determines whether the results include
Expand Down
17 changes: 9 additions & 8 deletions source/reference/command/explain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ Restrictions

.. include:: /includes/extracts/4.2-changes-agg-out-explain.rst

.. _explain-command-output:

Output
------

.. include:: /includes/fact-explain-results-categories.rst

For details on the output, see :doc:`/reference/explain-results`.

Examples
--------

Expand Down Expand Up @@ -216,11 +225,3 @@ all considered plans for an :dbcommand:`update` command:
}
)

.. _explain-command-output:

Output
------

.. include:: /includes/fact-explain-results-categories.rst

For details on the output, see :doc:`/reference/explain-results`.
17 changes: 9 additions & 8 deletions source/reference/method/cursor.explain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ verbosity mode.

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
-------

Expand All @@ -128,11 +137,3 @@ specified :method:`db.collection.find()` operation:
{ quantity: { $gt: 50 }, category: "apparel" }
).explain("executionStats")

.. _explain-cursor-method-output:

Output
------

.. include:: /includes/fact-explain-results-categories.rst

For details on the output, see :doc:`/reference/explain-results`.
50 changes: 27 additions & 23 deletions source/reference/method/db.collection.explain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ The :method:`db.collection.explain()` method wraps the

.. include:: /includes/fact-explain-methods-differences.rst

:method:`db.collection.explain().aggregate() <db.collection.explain()>` is equivalent to passing
the :ref:`explain <example-aggregate-method-explain-option>` option to
:method:`db.collection.explain().aggregate() <db.collection.explain()>`
is equivalent to passing the
:ref:`explain <example-aggregate-method-explain-option>` option to
the :method:`db.collection.aggregate()` method.

.. _explain-method-help:
Expand All @@ -176,10 +177,11 @@ To see the list of operations supported by

db.collection.explain().help()

:method:`db.collection.explain().find() <db.collection.explain()>` returns a cursor, which allows
for the chaining of query modifiers. To see the list of query modifiers
supported by :method:`db.collection.explain().find()
<db.collection.explain()>` as well as cursor-related methods, run:
:method:`db.collection.explain().find() <db.collection.explain()>`
returns a cursor, which allows for the chaining of query modifiers.
To see the list of query modifiers supported by
:method:`db.collection.explain().find() <db.collection.explain()>` as
well as cursor-related methods, run:

.. code-block:: javascript

Expand All @@ -188,6 +190,15 @@ supported by :method:`db.collection.explain().find()
You can chain multiple modifiers to ``db.collection.explain().find()``.
For an example, see :ref:`explain-find-modifiers`.

.. _explain-collection-method-output:

Output
------

.. include:: /includes/fact-explain-results-categories.rst

For details on the output, see :doc:`/reference/explain-results`.

.. _explain-method-examples:

Examples
Expand Down Expand Up @@ -250,9 +261,10 @@ all considered plans for the specified
Explain ``find()`` with Modifiers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:method:`db.collection.explain().find() <db.collection.explain()>` construct allows for the
chaining of query modifiers. For example, the following operation
provides information on the :method:`~db.collection.find()` method with
:method:`db.collection.explain().find() <db.collection.explain()>`
construct allows for the chaining of query modifiers. For example, the
following operation provides information on the
:method:`~db.collection.find()` method with
:method:`~cursor.sort()` and :method:`~cursor.hint()` query modifiers.

.. code-block:: javascript
Expand All @@ -271,22 +283,14 @@ shell:
Iterate the ``explain().find()`` Return Cursor
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:method:`db.collection.explain().find() <db.collection.explain()>` returns a cursor to the
explain results. If run interactively in the :binary:`~bin.mongo` shell,
the :binary:`~bin.mongo` shell automatically iterates the cursor using the
``.next()`` method. For scripts, however, you must explicitly call
``.next()`` (or its alias ``.finish()``) to return the results:
:method:`db.collection.explain().find() <db.collection.explain()>`
returns a cursor to the explain results. If run interactively in the
:binary:`~bin.mongo` shell, the :binary:`~bin.mongo` shell automatically
iterates the cursor using the ``.next()`` method. For scripts, however,
you must explicitly call ``.next()`` (or its alias ``.finish()``) to
return the results:

.. code-block:: javascript

var explainResult = db.products.explain().find( { category: "apparel" } ).next();

.. _explain-collection-method-output:

Output
------

.. include:: /includes/fact-explain-results-categories.rst

For details on the output, see :doc:`/reference/explain-results`.