<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Execute a database query on this server</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-driver-server.executecommand.html">MongoDB\Driver\Server::executeCommand</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-driver-server.executereadcommand.html">MongoDB\Driver\Server::executeReadCommand</a></div> <div class="up"><a href="class.mongodb-driver-server.html">MongoDB\Driver\Server</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongodb-driver-server.executequery" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoDB\Driver\Server::executeQuery</h1> <p class="verinfo">(mongodb >=1.0.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Server::executeQuery</span> — <span class="dc-title">Execute a database query on this server</span></p> </div> <div class="refsect1 description" id="refsect1-mongodb-driver-server.executequery-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">final</span> <span class="modifier">public</span> <span class="type"><span class="type MongoDB\Driver\Cursor">MongoDB\Driver\Cursor</span></span> <span class="methodname"><strong>MongoDB\Driver\Server::executeQuery</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$namespace</code></span> , <span class="methodparam"><span class="type"><span class="type MongoDB\Driver\Query">MongoDB\Driver\Query</span></span> <code class="parameter">$query</code></span> [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code><span class="initializer"> = array()</span></span> ] )</div> <p class="para rdfs-comment"> Executes the query on this server. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> The <em>"readPreference"</em> 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.executequery-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">namespace</code> (<span class="type"><a href="language.types.string.html" class="type string">string</a></span>)</dt> <dd> <p class="para"> A fully qualified namespace (e.g. <em>"databaseName.collectionName"</em>). </p> </dd> <dt> <code class="parameter">query</code> (<a href="class.mongodb-driver-query.html" class="classname">MongoDB\Driver\Query</a>)</dt> <dd> <p class="para"> The query 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>readPreference</td> <td><a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a></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><a href="class.mongodb-driver-session.html" class="classname">MongoDB\Driver\Session</a></td> <td> <p class="para"> A session to associate with the operation. </p> </td> </tr> </tbody> </table> </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-server.executequery-returnvalues"> <h3 class="title">Return Values</h3> <p class="para">Returns <a href="class.mongodb-driver-cursor.html" class="classname">MongoDB\Driver\Cursor</a> on success.</p> </div> <div class="refsect1 errors" id="refsect1-mongodb-driver-server.executequery-errors"> <h3 class="title">Errors/Exceptions</h3> <ul class="simplelist"> <li class="member">Throws <a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a> on argument parsing errors.</li><li class="member">Throws <a href="class.mongodb-driver-exception-connectionexception.html" class="classname">MongoDB\Driver\Exception\ConnectionException</a> if connection to the server fails (for reasons other than authentication).</li><li class="member">Throws <a href="class.mongodb-driver-exception-authenticationexception.html" class="classname">MongoDB\Driver\Exception\AuthenticationException</a> if authentication is needed and fails.</li> <li class="member">Throws <a href="class.mongodb-driver-exception-runtimeexception.html" class="classname">MongoDB\Driver\Exception\RuntimeException</a> on other errors (e.g. invalid query operators).</li> </ul> </div> <div class="refsect1 changelog" id="refsect1-mongodb-driver-server.executequery-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1.4.0</td> <td> The third parameter is now an <code class="parameter">options</code> array. For backwards compatibility, this paramater will still accept a <a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a> object. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-mongodb-driver-server.executequery-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><a href="class.mongodb-driver-cursor.html" class="classname">MongoDB\Driver\Cursor</a></li> <li class="member"><a href="class.mongodb-driver-query.html" class="classname">MongoDB\Driver\Query</a></li> <li class="member"><a href="class.mongodb-driver-readpreference.html" class="classname">MongoDB\Driver\ReadPreference</a></li> <li class="member"><span class="function"><a href="mongodb-driver-manager.executequery.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeQuery()</a> - Execute a database query</span></li> </ul> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-driver-server.executecommand.html">MongoDB\Driver\Server::executeCommand</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-driver-server.executereadcommand.html">MongoDB\Driver\Server::executeReadCommand</a></div> <div class="up"><a href="class.mongodb-driver-server.html">MongoDB\Driver\Server</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>