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

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

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.14.0.rc1
    • Component/s: Query
    • Labels:
    • Backwards Compatibility:
      Fully Compatible

      Description

      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
      

        Attachments

          Activity

            People

            Assignee:
            oleg.pudeyev Oleg Pudeyev
            Reporter:
            alex.bevilacqua Alex Bevilacqua
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: