Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2020

Set explain verbosity from Mongo::Collection::View::Explainable

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.14.0.rc1
    • Affects Version/s: None
    • Component/s: Query
    • 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
      

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: