123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongo/collection/view/explainable.rb

Overview

Defines explain related behavior for collection view.

Since:

  • 2.0.0

Constant Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#explained?Boolean (readonly, private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/collection/view/explainable.rb', line 65

def explained?
  !!options[:explain]
end

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

  • :verbose (true | false)

    The level of detail to return for MongoDB 2.6 servers.

  • :verbosity (String | Symbol)

    The type of information to return for MongoDB 3.0 and newer servers. 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

[ GitHub ]

  
# File 'lib/mongo/collection/view/explainable.rb', line 59

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

#explain_options(**opts) (private)

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :verbose (true | false)

    The level of detail to return for MongoDB 2.6 servers.

  • :verbosity (String | Symbol)

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

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/collection/view/explainable.rb', line 75

def explain_options(**opts)
  explain_limit = limit || 0
  # Note: opts will never be nil here.
  if Symbol === opts[:verbosity]
    opts[:verbosity] = Utils.camelize(opts[:verbosity])
  end
  { limit: -explain_limit.abs, explain: opts }
end