Module: Mongo::Collection::View::Explainable

Included in:
Mongo::Collection::View, Aggregation::Behavior
Defined in:
lib/mongo/collection/view/explainable.rb

Overview

Defines explain related behavior for collection view.

Since:

  • 2.0.0

Constant Summary collapse

QUERY_PLANNER =

The query planner verbosity constant.

Since:

  • 2.2.0

'queryPlanner'
EXECUTION_STATS =

The execution stats verbosity constant.

Since:

  • 2.2.0

'executionStats'
ALL_PLANS_EXECUTION =

The all plans execution verbosity constant.

Since:

  • 2.2.0

'allPlansExecution'

Instance Method Summary collapse

Instance Method Details

#explain(**opts) ⇒ Hash

Get the query plan for the query.

Examples:

Get the query plan for the query with execution statistics.

view.explain(verbosity: :execution_stats)

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :verbosity (String | Symbol)

    The type of information to return. If the value is a symbol, it will be stringified and converted from underscore style to camel case style (e.g. :query_planner => “queryPlanner”).

Returns:

  • (Hash)

    A single document with the query plan.

See Also:

Since:

  • 2.0.0



54
55
56
# File 'lib/mongo/collection/view/explainable.rb', line 54

def explain(**opts)
  self.class.new(collection, selector, options.merge(explain_options(**opts))).first
end