Skip to content

Commit 16e8f19

Browse files
p-mongop
andauthored
RUBY-2020 Set explain verbosity from Mongo::Collection::View::Explainable (#2108)
* RUBY-2020 Set explain verbosity from Mongo::Collection::View::Explainable * typo fix Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 564d373 commit 16e8f19

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

source/tutorials/ruby-driver-crud-operations.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,39 @@ when querying and their corresponding methods as examples.
209209
each ``GETMORE`` operation.
210210
* - ``comment(String)``
211211
- Adds a comment to the query.
212+
213+
* - ``explain(**opts)``
214+
- Returns the query plan for the query. Pass the :manual:`explain options
215+
</reference/command/explain/>` via the keyword arguments using symbol
216+
keys.
217+
218+
.. code-block:: ruby
219+
220+
# All server versions - default explain behavior
221+
client[:artists].find.explain
222+
223+
# MongoDB 3.0 and newer
224+
client[:artists].find.explain(verbosity: :query_planner)
225+
client[:artists].find.explain(verbosity: :execution_stats)
226+
client[:artists].find.explain(verbosity: :all_plans_execution)
227+
228+
# Alternative syntax using camel case
229+
client[:artists].find.explain(verbosity: "queryPlanner")
230+
client[:artists].find.explain(verbosity: "executionStats")
231+
client[:artists].find.explain(verbosity: "allPlansExecution")
232+
233+
# MongoDB 2.6
234+
client[:artists].find.explain(verbose: true)
235+
236+
.. note::
237+
238+
The information returned by the server for the ``explain`` command
239+
varies with server version and deployment topology. The driver's
240+
``explain`` method returns whatever the server provided.
241+
242+
**The return value of ``explain`` method is not part of the driver's
243+
public API and depends on the server version and deployment topology.**
244+
212245
* - ``hint(Hash)``
213246
- Provides the query with an
214247
:manual:`index hint</reference/method/cursor.hint/>` to use.

0 commit comments

Comments
 (0)