<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.mongodb-driver-server.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'mongodb-driver-server.executereadcommand.php',
    1 => 'MongoDB\\Driver\\Server::executeReadCommand',
    2 => 'Execute a database command that reads on this server',
  ),
  'up' => 
  array (
    0 => 'class.mongodb-driver-server.php',
    1 => 'MongoDB\\Driver\\Server',
  ),
  'prev' => 
  array (
    0 => 'mongodb-driver-server.executequery.php',
    1 => 'MongoDB\\Driver\\Server::executeQuery',
  ),
  'next' => 
  array (
    0 => 'mongodb-driver-server.executereadwritecommand.php',
    1 => 'MongoDB\\Driver\\Server::executeReadWriteCommand',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/mongodb/driver/server/executereadcommand.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="mongodb-driver-server.executereadcommand" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoDB\Driver\Server::executeReadCommand</h1>
  <p class="verinfo">(mongodb &gt;=1.4.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Server::executeReadCommand</span> &mdash; <span class="dc-title">Execute a database command that reads on this server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongodb-driver-server.executereadcommand-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><strong>MongoDB\Driver\Server::executeReadCommand</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$db</code></span>, <span class="methodparam"><span class="type"><a href="class.mongodb-driver-command.php" class="type MongoDB\Driver\Command">MongoDB\Driver\Command</a></span> <code class="parameter">$command</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.array.php" class="type array">array</a></span></span> <code class="parameter">$options</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="class.mongodb-driver-cursor.php" class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</a></span></div>

  <p class="simpara">
   Executes the command on this server, irrespective of the
   <code class="literal">&quot;readPreference&quot;</code> option.
  </p>
  <p class="simpara">
   This method will apply logic that is specific to commands that read (e.g.
   <a href="https://www.mongodb.com/docs/manual/reference/command/distinct/" class="link external">&raquo;&nbsp;distinct</a>).
   Default values for the <code class="literal">&quot;readPreference&quot;</code> and
   <code class="literal">&quot;readConcern&quot;</code> options will be inferred from an active
   transaction (indicated by the <code class="literal">&quot;session&quot;</code> option), followed
   by the <a href="mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-uri" class="link">connection URI</a>.
  </p>
  
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <span class="simpara">
    The <code class="literal">&quot;readPreference&quot;</code> option does not control the server
    to which the driver issues the operation; it will always be executed on
    this server object. Instead, it may be used when issuing the operation to a
    secondary (from a replica set connection, not standalone) or mongos node to
    ensure that the driver sets the wire protocol accordingly or adds the read
    preference to the operation, respectively.
   </span>
  </p></blockquote>

 </div>


 <div class="refsect1 parameters" id="refsect1-mongodb-driver-server.executereadcommand-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
   
    <dt><code class="parameter">db</code> (<span class="type"><a href="language.types.string.php" class="type string">string</a></span>)</dt>
    <dd>
     <p class="para">
      The name of the database on which to execute the command.
     </p>
    </dd>
   

   
   
    <dt><code class="parameter">command</code> (<span class="classname"><a href="class.mongodb-driver-command.php" class="classname">MongoDB\Driver\Command</a></span>)</dt>
    <dd>
     <p class="para">
      The command to execute.
     </p>
    </dd>
   

   
    <dt><code class="parameter">options</code></dt>
    <dd>
     <p class="para">
      <table class="doctable table">
       <caption><strong>options</strong></caption>
       
        <thead>
         <tr>
          <th>Option</th>
          <th>Type</th>
          <th>Description</th>
         </tr>

        </thead>

        <tbody class="tbody">
         
         <tr>
          <td>readConcern</td>
          <td><span class="classname"><a href="class.mongodb-driver-readconcern.php" class="classname">MongoDB\Driver\ReadConcern</a></span></td>
          <td>
           <p class="para">
            A read concern to apply to the operation.
           </p>
           <p class="para">
            This option is available in MongoDB 3.2+ and will result in an
            exception at execution time if specified for an older server
            version.
           </p>
          </td>
         </tr>


         
         <tr>
          <td>readPreference</td>
          <td><span class="classname"><a href="class.mongodb-driver-readpreference.php" class="classname">MongoDB\Driver\ReadPreference</a></span></td>
          <td>
           <p class="para">
            A read preference to use for selecting a server for the operation.
           </p>
          </td>
         </tr>


         
         <tr>
          <td>session</td>
          <td><span class="classname"><a href="class.mongodb-driver-session.php" class="classname">MongoDB\Driver\Session</a></span></td>
          <td>
           <p class="para">
            A session to associate with the operation.
           </p>
          </td>
         </tr>


        </tbody>
       
      </table>

     </p>
     
     <div class="warning"><strong class="warning">Avviso</strong>
      <p class="para">
       If you are using a <code class="literal">&quot;session&quot;</code> which has a transaction
       in progress, you cannot specify a <code class="literal">&quot;readConcern&quot;</code> or
       <code class="literal">&quot;writeConcern&quot;</code> option. This will result in an
       <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span>
       being thrown. Instead, you should set these two options when you create
       the transaction with
       <span class="methodname"><a href="mongodb-driver-session.starttransaction.php" class="methodname">MongoDB\Driver\Session::startTransaction()</a></span>.
      </p>
     </div>

    </dd>
   
  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-server.executereadcommand-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">Returns <span class="classname"><a href="class.mongodb-driver-cursor.php" class="classname">MongoDB\Driver\Cursor</a></span> on success.</p>
 </div>


 <div class="refsect1 errors" id="refsect1-mongodb-driver-server.executereadcommand-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <ul class="simplelist">
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> if the <code class="literal">&quot;session&quot;</code> option is used with an associated transaction in combination with a <code class="literal">&quot;readConcern&quot;</code> or <code class="literal">&quot;writeConcern&quot;</code> option.</li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-invalidargumentexception.php" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a></span> on argument parsing errors.</li><li>Throws <span class="classname"><a href="class.mongodb-driver-exception-connectionexception.php" class="classname">MongoDB\Driver\Exception\ConnectionException</a></span> if connection to the server fails (for reasons other than authentication).</li><li>Throws <span class="classname"><a href="class.mongodb-driver-exception-authenticationexception.php" class="classname">MongoDB\Driver\Exception\AuthenticationException</a></span> if authentication is needed and fails.</li>
   <li>Throws <span class="classname"><a href="class.mongodb-driver-exception-runtimeexception.php" class="classname">MongoDB\Driver\Exception\RuntimeException</a></span> on other errors (e.g. invalid command).</li>
  </ul>
 </div>


 <div class="refsect1 seealso" id="refsect1-mongodb-driver-server.executereadcommand-seealso">
  <h3 class="title">Vedere anche:</h3>
  <ul class="simplelist">
   <li><span class="classname"><a href="class.mongodb-driver-command.php" class="classname">MongoDB\Driver\Command</a></span></li>
   <li><span class="classname"><a href="class.mongodb-driver-cursor.php" class="classname">MongoDB\Driver\Cursor</a></span></li>
   <li><span class="function"><a href="mongodb-driver-server.executecommand.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Server::executeCommand()</a> - Execute a database command on this server</span></li>
   <li><span class="function"><a href="mongodb-driver-server.executereadwritecommand.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Server::executeReadWriteCommand()</a> - Execute a database command that reads and writes on this server</span></li>
   <li><span class="function"><a href="mongodb-driver-server.executewritecommand.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Server::executeWriteCommand()</a> - Execute a database command that writes on this server</span></li>
   <li><span class="function"><a href="mongodb-driver-manager.executereadcommand.php" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeReadCommand()</a> - Execute a database command that reads</span></li>
  </ul>
 </div>


</div><?php manual_footer($setup); ?>