@@ -4,6 +4,12 @@ Access Data From a Cursor
44
55.. default-domain:: mongodb
66
7+ .. contents:: On this page
8+ :local:
9+ :backlinks: none
10+ :depth: 2
11+ :class: singlecol
12+
713Read operations that return multiple documents do not immediately return
814all values matching the query. Because a query can potentially match
915large number of documents, we need to be able to access or store the
@@ -25,7 +31,7 @@ instance of a ``FindIterable``.
2531
2632A ``FindIterable`` consists of documents matched by your search criteria
2733and allows you to further specify which documents to see by setting
28- paramaters though methods.
34+ parameters though methods.
2935
3036Terminal Methods
3137----------------
@@ -37,8 +43,8 @@ operation.
3743First
3844~~~~~
3945
40- Use the :java-docs:` first() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html# first()>`
41- method to retireve the first document in your query results:
46+ Use the `` first()`` method to retrieve the first document in your query
47+ results:
4248
4349.. literalinclude:: /includes/fundamentals/code-snippets/Cursor.java
4450 :language: java
@@ -52,8 +58,7 @@ document, such as when filtering by a unique index.
5258Into
5359~~~~
5460
55- Use the :java-docs:`into() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#into(A)>`
56- method to store your query results in a ``List``:
61+ Use the ``into()`` method to store your query results in a ``List``:
5762
5863.. literalinclude:: /includes/fundamentals/code-snippets/Cursor.java
5964 :language: java
@@ -67,9 +72,8 @@ of documents that can fit into available memory.
6772Cursor
6873~~~~~~
6974
70- Use the :java-docs:`cursor() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#cursor()>`
71- method to iterate through fetched documents and ensure that the cursor
72- closes if there is an early termination:
75+ Use the ``cursor()`` method to iterate through fetched documents and
76+ ensure that the cursor closes if there is an early termination:
7377
7478.. code-block:: java
7579 :copyable: true
@@ -78,6 +82,51 @@ closes if there is an early termination:
7882
7983For more information on how to ensure a cursor closes, see the :ref:`cursor cleanup section <cursor_cleanup>`.
8084
85+ Explain
86+ ~~~~~~~
87+
88+ Use the ``explain()`` method to view information about how MongoDB
89+ executes your operation.
90+
91+ The ``explain()`` method returns **execution plans** and performance
92+ statistics. An execution plan is a potential way MongoDB
93+ can complete an operation. The ``explain()`` method provides both the
94+ winning plan (the plan MongoDB executed) and rejected plans.
95+
96+ .. include:: /includes/fundamentals/explain-verbosity.rst
97+
98+ The following example prints the JSON representation of the
99+ winning plan for aggregation stages that produce execution plans:
100+
101+ .. literalinclude:: /includes/fundamentals/code-snippets/Cursor.java
102+ :language: java
103+ :dedent:
104+ :start-after: begin explainExample
105+ :end-before: end explainExample
106+
107+ The above code snippet should produce the following output:
108+
109+ .. code-block:: none
110+ :copyable: false
111+
112+ { "stage": "COLLSCAN", "direction": "forward" }
113+
114+ For more information on the explain operation, see the following
115+ Server Manual Entries:
116+
117+ - :manual:`Explain Output </reference/explain-results/>`
118+ - :manual:`Query Plans </core/query-plans/>`
119+
120+ For more information about the methods and classes mentioned in this
121+ section, see the following API documentation:
122+
123+ - :java-docs:`first() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#first()>`
124+ - :java-docs:`into() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#into(A)>`
125+ - :java-docs:`cursor() <apidocs/mongodb-driver-sync/com/mongodb/client/MongoIterable.html#cursor()>`
126+ - :java-docs:`explain() <apidocs/mongodb-driver-sync/com/mongodb/client/FindIterable.html#explain()>`
127+ - :java-core-api:`ExplainVerbosity <com/mongodb/ExplainVerbosity>`
128+
129+
81130Usage Patterns
82131--------------
83132
0 commit comments