-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Query
-
(copied to CRM)
-
Fully Compatible
Mongo::Collection::View::Explainable#explain (also called by Mongoid via Mongoid::Contextual::Mongo#explain) does not allow explain verbosity to be configured.
For example, to accomplish something like:
# Proposed explain invocation with a verbosity parameter from Mongoid User.where(_id: "5db7231f03881d09d23cca7d").explain(:query_planner)
the workaround would be as follows:
# First we need the database reference from the Ruby driver (not Mongoid) db = User.collection.database # Next we need to generate the `find` command that will be sent to the explain method cmd = { find: 'users', filter: { _id: "5db7231f03881d09d23cca7d" } } # We then send the command params to the explain command with our desired verbosity result = db.command(explain: cmd, verbosity: 'queryPlanner') # Since the result is a Mongo::Operation::Result (not a hash) we have to extract the # results from the `documents` array would contain the explain plan result.documents.first