<!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>Start a new client session for use with this client</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="mongodb-driver-manager.selectserver.html">MongoDB\Driver\Manager::selectServer</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongodb-driver-command.html">MongoDB\Driver\Command</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.startsession" class="refentry"> <div class="refnamediv"> <h1 class="refname">MongoDB\Driver\Manager::startSession</h1> <p class="verinfo">(mongodb >=1.4.0)</p><p class="refpurpose"><span class="refname">MongoDB\Driver\Manager::startSession</span> — <span class="dc-title">Start a new client session for use with this client</span></p> </div> <div class="refsect1 description" id="refsect1-mongodb-driver-manager.startsession-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\Session">MongoDB\Driver\Session</span></span> <span class="methodname"><strong>MongoDB\Driver\Manager::startSession</strong></span> ([ <span class="methodparam"><span class="type">array</span> <code class="parameter">$options</code></span> ] )</div> <p class="para rdfs-comment"> Creates a <a href="class.mongodb-driver-session.html" class="classname">MongoDB\Driver\Session</a> for the given options. The session may then be specified when executing commands, queries, and write operations. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara"> A <a href="class.mongodb-driver-session.html" class="classname">MongoDB\Driver\Session</a> can only be used with the <a href="class.mongodb-driver-manager.html" class="classname">MongoDB\Driver\Manager</a> from which it was created. </span> </p></blockquote> </div> <div class="refsect1 parameters" id="refsect1-mongodb-driver-manager.startsession-parameters"> <h3 class="title">Parameters</h3> <dl> <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> <th>Default</th> </tr> </thead> <tbody class="tbody"> <tr> <td>causalConsistency</td> <td><span class="type"><a href="language.types.boolean.html" class="type boolean">boolean</a></span></td> <td> <p class="para"> Configure causal consistency in a session. If <strong><code>TRUE</code></strong>, each operation in the session will be causally ordered after the previous read or write operation. Set to <strong><code>FALSE</code></strong> to disable causal consistency. </p> <p class="para"> See <a href="https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency" class="link external">» Casual Consistency</a> in the MongoDB manual for more information. </p> </td> <td><strong><code>TRUE</code></strong></td> </tr> <tr> <td>defaultTransactionOptions</td> <td><span class="type"><a href="language.types.array.html" class="type array">array</a></span></td> <td> <p class="para"> Default options to apply to newly created transactions. These options are used unless they are overridden when a transaction is started with different value for each option. </p> <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><a href="class.mongodb-driver-readconcern.html" class="classname">MongoDB\Driver\ReadConcern</a></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><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>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> <p class="para"> This option is available in MongoDB 4.0+. </p> </td> <td><em>[]</em></td> </tr> </tbody> </table> </p> </dd> </dl> </div> <div class="refsect1 returnvalues" id="refsect1-mongodb-driver-manager.startsession-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a <a href="class.mongodb-driver-session.html" class="classname">MongoDB\Driver\Session</a>. </p> </div> <div class="refsect1 errors" id="refsect1-mongodb-driver-manager.startsession-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-runtimeexception.html" class="classname">MongoDB\Driver\Exception\RuntimeException</a> if the session could not be created (e.g. libmongoc does not support crypto).</li> </ul> </div> <div class="refsect1 changelog" id="refsect1-mongodb-driver-manager.startsession-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.5.0</td> <td> <p class="para"> The <em>"defaultTransactionOptions"</em> option was added. </p> </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 seealso" id="refsect1-mongodb-driver-manager.startsession-seealso"> <h3 class="title">See Also</h3> <ul class="simplelist"> <li class="member"><a href="class.mongodb-driver-session.html" class="classname">MongoDB\Driver\Session</a></li> <li class="member"><a href="https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/#causal-consistency" class="link external">» Casual Consistency</a> in the MongoDB manual</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.selectserver.html">MongoDB\Driver\Manager::selectServer</a></div> <div class="next" style="text-align: right; float: right;"><a href="class.mongodb-driver-command.html">MongoDB\Driver\Command</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>