<!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 command that writes</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-driver-manager.executereadwritecommand.html">MongoDB\Driver\Manager::executeReadWriteCommand</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-driver-manager.getreadconcern.html">MongoDB\Driver\Manager::getReadConcern</a></div> <div class="up"><a href="class.mongodb-driver-manager.html">MongoDB\Driver\Manager</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="mongodb-driver-manager.executewritecommand" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoDB\Driver\Manager::executeWriteCommand</h1> <p class="verinfo">(mongodb >=1.4.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Manager::executeWriteCommand</span> — <span class="dc-title">Execute a database command that writes</span></p> </div> <div class="refsect1 description" id="refsect1-mongodb-driver-manager.executewritecommand-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\Manager::executeWriteCommand</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$db</code></span> , <span class="methodparam"><span class="type"><span class="type MongoDB\Driver\Command">MongoDB\Driver\Command</span></span> <code class="parameter">$command</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 command on the primary server. </p> <p class="para"> This method will apply logic that is specific to commands that write (e.g. <a href="https://docs.mongodb.com/manual/reference/command/drop/" class="link external">» drop</a>) and take the MongoDB server version into account. The <em>"writeConcern"</em> option will default to the corresponding value from the <a href="mongodb-driver-manager.construct.html#mongodb-driver-manager.construct-uri" class="link">MongoDB Connection URI</a>. </p> </div> <div class="refsect1 parameters" id="refsect1-mongodb-driver-manager.executewritecommand-parameters"> <h3 class="title">Parameters</h3> <dl> <dt> <code class="parameter">db</code> (<span class="type"><a href="language.types.string.html" 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> (<a href="class.mongodb-driver-command.html" class="classname">MongoDB\Driver\Command</a>)</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>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> <tr> <td>writeConcern</td> <td><a href="class.mongodb-driver-writeconcern.html" class="classname">MongoDB\Driver\WriteConcern</a></td> <td> <p class="para"> A write concern to apply to the operation. </p> </td> </tr> </tbody> </table> </p> <div class="warning"><strong class="warning">Warning</strong> <p class="para"> If you are using a <em>"session"</em> which has a transaction in progress, you cannot specify a <em>"readConcern"</em> or <em>"writeConcern"</em> option. This will result in an <a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a> being thrown. Instead, you should set these two options when you create the transaction with <span class="methodname"><a href="mongodb-driver-session.starttransaction.html" class="methodname">MongoDB\Driver\Session::startTransaction()</a></span>. </p> </div> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-manager.executewritecommand-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-manager.executewritecommand-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> if the <em>"session"</em> option is used with an associated transaction in combination with a <em>"readConcern"</em> or <em>"writeConcern"</em> option.</li> <li class="member">Throws <a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a> if the <em>"session"</em> option is used in combination with an unacknowledged write concern.</li> <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 command).</li> </ul> </div> <div class="refsect1 changelog" id="refsect1-mongodb-driver-manager.executewritecommand-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.4</td> <td> <a href="class.mongodb-driver-exception-invalidargumentexception.html" class="classname">MongoDB\Driver\Exception\InvalidArgumentException</a> will be thrown if the <em>"session"</em> option is used in combination with an unacknowledged write concern. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-mongodb-driver-manager.executewritecommand-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><a href="class.mongodb-driver-command.html" class="classname">MongoDB\Driver\Command</a></li> <li class="member"><a href="class.mongodb-driver-cursor.html" class="classname">MongoDB\Driver\Cursor</a></li> <li class="member"><span class="function"><a href="mongodb-driver-manager.executecommand.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeCommand()</a> - Execute a database command</span></li> <li class="member"><span class="function"><a href="mongodb-driver-manager.executereadcommand.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeReadCommand()</a> - Execute a database command that reads</span></li> <li class="member"><span class="function"><a href="mongodb-driver-manager.executereadwritecommand.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Manager::executeReadWriteCommand()</a> - Execute a database command that reads and writes</span></li> <li class="member"><span class="function"><a href="mongodb-driver-server.executewritecommand.html" class="function" rel="rdfs-seeAlso">MongoDB\Driver\Server::executeWriteCommand()</a> - Execute a database command that writes on this server</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-manager.executereadwritecommand.html">MongoDB\Driver\Manager::executeReadWriteCommand</a></div> <div class="next" style="text-align: right; float: right;"><a href="mongodb-driver-manager.getreadconcern.html">MongoDB\Driver\Manager::getReadConcern</a></div> <div class="up"><a href="class.mongodb-driver-manager.html">MongoDB\Driver\Manager</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>