lib/mongo/database.rb
def command(operation, opts = {})
      opts = opts.dup
      execution_opts = opts.delete(:execution_options) || {}

      txn_read_pref = if opts[:session] && opts[:session].in_transaction?
        opts[:session].txn_read_preference
      else
        nil
      end
      txn_read_pref ||= opts[:read] || ServerSelector::PRIMARY
      Lint.validate_underscore_read_preference(txn_read_pref)
      selector = ServerSelector.get(txn_read_pref)

      client.send(:with_session, opts) do |session|
        server = selector.select_server(cluster, nil, session)
        op = Operation::Command.new(
          :selector => operation.dup,
          :db_name => name,
          :read => selector,
          :session => session
        )

        op.execute(server,
          context: Operation::Context.new(client: client, session: session),
          options: execution_opts)
      end
    end
# Execute a command on the database.
#
# @example Execute a command.
#   database.command(:hello => 1)
#
# @param [ Hash ] operation The command to execute.
# @param [ Hash ] opts The command options.
#
# @option opts :read [ Hash ] The read preference for this command.
# @option opts :session [ Session ] The session to use for this command.
# @option opts :execution_options [ Hash ] Options to pass to the code that
#   executes this command. This is an internal option and is subject to
#   change.
#   - :deserialize_as_bson [ Boolean ] Whether to deserialize the response
#     to this command using BSON types intead of native Ruby types wherever
#     possible.
#
# @return [ Mongo::Operation::Result ] The result of the command execution.
Execute a command on the database.
Execute a command on the database .
def command(operation, opts = {})
      opts = opts.dup
      execution_opts = opts.delete(:execution_options) || {}
      txn_read_pref = if opts[:session] && opts[:session].in_transaction?
        opts[:session].txn_read_preference
      else
        nil
      end
      txn_read_pref ||= opts[:read] || ServerSelector::PRIMARY
      Lint.validate_underscore_read_preference(txn_read_pref)
      selector = ServerSelector.get(txn_read_pref)
      client.send(:with_session, opts) do |session|
        server = selector.select_server(cluster, nil, session)
        op = Operation::Command.new(
          :selector => operation.dup,
          :db_name => name,
          :read => selector,
          :session => session
        )
        op.execute(server,
          context: Operation::Context.new(client: client, session: session),
          options: execution_opts)
      end
    end
def command ( operation , opts = { } ) opts = opts . dup execution_opts = opts . delete ( :execution_options ) || { } txn_read_pref = if opts [ :session ] && opts [ :session ] . in_transaction? opts [ :session ] . txn_read_preference else nil end txn_read_pref ||= opts [ :read ] || ServerSelector :: PRIMARY Lint . validate_underscore_read_preference ( txn_read_pref ) selector = ServerSelector . get ( txn_read_pref ) client . send ( :with_session , opts ) do | session | server = selector . select_server ( cluster , nil , session ) op = Operation :: Command . new ( :selector => operation . dup , :db_name => name , :read => selector , :session => session ) op . execute ( server , context : Operation :: Context . new ( client : client , session : session ) , options : execution_opts ) end end
Execute a command on the database.
Execute a command on the database .
The result of the command execution.
The result of the command execution .
 Mongo::Operation::Result 
operation
opts
:execution_options  Options to pass to the code that executes this command. This is an internal option and is subject to change. - :deserialize_as_bson [ Boolean ] Whether to deserialize the response to this command using BSON types intead of native Ruby types wherever possible.
: execution_options Options to pass to the code that executes this command . This is an internal option and is subject to change . - : deserialize_as_bson [ Boolean ] Whether to deserialize the response to this command using BSON types intead of native Ruby types wherever possible .
opts The command options.
opts The command options .
example
Execute a command. database.command(:hello => 1)
Execute a command . database . command ( : hello = > 1 )