<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->

<refentry xml:id="mongodb-driver-manager.startsession" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
 <refnamediv>
  <refname>MongoDB\Driver\Manager::startSession</refname>
  <refpurpose>Start a new client session for use with this client</refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <modifier>final</modifier> <modifier>public</modifier> <type>MongoDB\Driver\Session</type><methodname>MongoDB\Driver\Manager::startSession</methodname>
   <methodparam choice="opt"><type class="union"><type>array</type><type>null</type></type><parameter>options</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Creates a <classname>MongoDB\Driver\Session</classname> for the given
   options. The session may then be specified when executing commands, queries,
   and write operations.
  </para>
  <note>
   <simpara>
    A <classname>MongoDB\Driver\Session</classname> can only be used with the
    <classname>MongoDB\Driver\Manager</classname> from which it was created.
   </simpara>
  </note>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <variablelist>
   <varlistentry>
    <term><parameter>options</parameter></term>
    <listitem>
     <para>
      <table>
       <title>options</title>
       <tgroup cols="4">
        <thead>
         <row>
          <entry>Option</entry>
          <entry>Type</entry>
          <entry>Description</entry>
          <entry>Default</entry>
         </row>
        </thead>
        <tbody>
         <row>
          <entry>causalConsistency</entry>
          <entry><type>bool</type></entry>
          <entry>
           <para>
            Configure causal consistency in a session. If &true;, each operation
            in the session will be causally ordered after the previous read or
            write operation. Set to &false; to disable causal consistency.
           </para>
           <para>
            See
            <link xlink:href="&url.mongodb.docs;core/read-isolation-consistency-recency/#causal-consistency">Casual Consistency</link>
            in the MongoDB manual for more information.
           </para>
          </entry>
          <entry>&true;</entry>
         </row>
         <row>
          <entry>defaultTransactionOptions</entry>
          <entry><type>array</type></entry>
          <entry>
           <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.
           </para>
           <para>
            <table>
             <title>options</title>
             <tgroup cols="3">
              <thead>
               <row>
                <entry>Option</entry>
                <entry>Type</entry>
                <entry>Description</entry>
               </row>
              </thead>
              <tbody>
               &mongodb.option.maxCommitTimeMS;
               &mongodb.option.readConcern;
               &mongodb.option.readPreference;
               &mongodb.option.writeConcern;
              </tbody>
             </tgroup>
            </table>
           </para>
           <para>
            This option is available in MongoDB 4.0+.
           </para>
          </entry>
          <entry><literal>[]</literal></entry>
         </row>
         <row>
          <entry>snapshot</entry>
          <entry><type>bool</type></entry>
          <entry>
           <para>
            Configure snapshot reads in a session. If &true;, a timestamp will
            be obtained from the first supported read operation in the session
            (i.e. <literal>find</literal>, <literal>aggregate</literal>, or
            unsharded <literal>distinct</literal>). Subsequent read operations
            within the session will then utilize a <literal>"snapshot"</literal>
            read concern level to read majority-committed data from that
            timestamp. Set to &false; to disable snapshot reads.
           </para>
           <para>
            Snapshot reads require MongoDB 5.0+ and cannot be used with causal
            consistency, transactions, or write operations. If
            <literal>"snapshot"</literal> is &true;,
            <literal>"causalConsistency"</literal> will default to &false;.
           </para>
           <para>
            See
            <link xlink:href="&url.mongodb.docs;reference/read-concern-snapshot/#read-concern-and-atclustertime">Read Concern "snapshot"</link>
            in the MongoDB manual for more information.
           </para>
          </entry>
          <entry>&false;</entry>
         </row>
        </tbody>
       </tgroup>
      </table>
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a <classname>MongoDB\Driver\Session</classname>.
  </para>
 </refsect1>

 <refsect1 role="errors">
  &reftitle.errors;
  <simplelist>
   &mongodb.throws.argumentparsing;
   <member>Throws <classname>MongoDB\Driver\Exception\InvalidArgumentException</classname> if the <literal>"causalConsistency"</literal> and <literal>"snapshot"</literal> options are both &true;.</member>
   <member>Throws <classname>MongoDB\Driver\Exception\RuntimeException</classname> if the session could not be created (e.g. libmongoc does not support crypto).</member>
  </simplelist>
 </refsect1>

 <refsect1 role="changelog">
  &reftitle.changelog;
  <para>
   <informaltable>
    <tgroup cols="2">
     <thead>
      <row>
       <entry>&Version;</entry>
       <entry>&Description;</entry>
      </row>
     </thead>
     <tbody>
      <row>
       <entry>PECL mongodb 1.11.0</entry>
       <entry>
        <para>
         The <literal>"snapshot"</literal> option was added.
        </para>
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.6.0</entry>
       <entry>
        <para>
         The <literal>"maxCommitTimeMS"</literal> option was added to
         <literal>"defaultTransactionOptions"</literal>.
        </para>
       </entry>
      </row>
      <row>
       <entry>PECL mongodb 1.5.0</entry>
       <entry>
        <para>
         The <literal>"defaultTransactionOptions"</literal> option was added.
        </para>
       </entry>
      </row>
     </tbody>
    </tgroup>
   </informaltable>
  </para>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <simplelist>
   <member><classname>MongoDB\Driver\Session</classname></member>
   <member><link xlink:href="&url.mongodb.docs;core/read-isolation-consistency-recency/#causal-consistency">Casual Consistency</link> in the MongoDB manual</member>
  </simplelist>
 </refsect1>

</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
