<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/mongodb.mongodb.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'class.mongodb-driver-readconcern.php',
    1 => 'MongoDB\\Driver\\ReadConcern',
    2 => 'The MongoDB\\Driver\\ReadConcern class',
  ),
  'up' => 
  array (
    0 => 'mongodb.mongodb.php',
    1 => 'MongoDB\\Driver',
  ),
  'prev' => 
  array (
    0 => 'mongodb-driver-readpreference.gettagsets.php',
    1 => 'MongoDB\\Driver\\ReadPreference::getTagSets',
  ),
  'next' => 
  array (
    0 => 'mongodb-driver-readconcern.bsonserialize.php',
    1 => 'MongoDB\\Driver\\ReadConcern::bsonSerialize',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/mongodb/mongodb/driver/readconcern.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.mongodb-driver-readconcern.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.mongodb-driver-readconcern" class="reference">

 <h1 class="title">The MongoDB\Driver\ReadConcern class</h1>
 

 <div class="partintro"><p class="verinfo">(mongodb &gt;=1.1.0)</p>


  <div class="section" id="mongodb-driver-readconcern.intro">
   <h2 class="title">Introduction</h2>
   <p class="para">
    <span class="classname"><strong class="classname">MongoDB\Driver\ReadConcern</strong></span> controls the level of
    isolation for read operations for replica sets and replica set shards. This
    option requires MongoDB 3.2 or later.
   </p>
  </div>


  <div class="section" id="mongodb-driver-readconcern.synopsis">
   <h2 class="title">Class synopsis</h2>


   <div class="classsynopsis">
    <span class="ooclass"><strong class="classname"></strong></span>


    <div class="classsynopsisinfo">
     <span class="modifier">final</span>
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">MongoDB\Driver\ReadConcern</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <a href="class.mongodb-bson-serializable.php" class="interfacename">MongoDB\BSON\Serializable</a></span><span class="oointerface">,  <a href="class.serializable.php" class="interfacename">Serializable</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.linearizable"><var class="varname">AVAILABLE</var></a></var><span class="initializer"> = &quot;available&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.linearizable"><var class="varname">LINEARIZABLE</var></a></var><span class="initializer"> = &quot;linearizable&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.local"><var class="varname">LOCAL</var></a></var><span class="initializer"> = &quot;local&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.majority"><var class="varname">MAJORITY</var></a></var><span class="initializer"> = &quot;majority&quot;</span>;</div>

    <div class="fieldsynopsis"><span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.snapshot"><var class="varname">SNAPSHOT</var></a></var><span class="initializer"> = &quot;snapshot&quot;</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-readconcern.bsonserialize.php" class="methodname">bsonSerialize</a></span>(): <span class="type"><a href="class.stdclass.php" class="type stdClass">stdClass</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-readconcern.construct.php" class="methodname">__construct</a></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.string.php" class="type string">string</a></span></span> <code class="parameter">$level</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>)</div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-readconcern.getlevel.php" class="methodname">getLevel</a></span>(): <span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.string.php" class="type string">string</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">final</span> <span class="modifier">public</span> <span class="methodname"><a href="mongodb-driver-readconcern.isdefault.php" class="methodname">isDefault</a></span>(): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

   }</div>


  </div>


  <div class="section" id="mongodb-driver-readconcern.constants">
   <h2 class="title">Predefined Constants</h2>
   <dl>

    
     <dt id="mongodb-driver-readconcern.constants.available"><strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.available">MongoDB\Driver\ReadConcern::AVAILABLE</a></code></strong></dt>
     <dd>
      <p class="para">
       Default for reads against secondaries when
       <code class="literal">afterClusterTime</code>and <code class="literal">level</code> are
       unspecified.
      </p>
      <p class="para">
       The query returns the instance&#039;s most recent data. Provides no
       guarantee that the data has been written to a majority of the replica set
       members (i.e. may be rolled back).
      </p>
      <p class="para">
       For unsharded collections (including collections in a standalone
       deployment or a replica set deployment), <code class="literal">&quot;local&quot;</code> and
       <code class="literal">&quot;available&quot;</code> read concerns behave identically.
      </p>
      <p class="para">
       For a sharded cluster, <code class="literal">&quot;available&quot;</code> read concern
       provides greater tolerance for partitions since it does not wait to
       ensure consistency guarantees. However, a query with
       <code class="literal">&quot;available&quot;</code> read concern may return orphan documents
       if the shard is undergoing chunk migrations since the
       <code class="literal">&quot;available&quot;</code> read concern, unlike
       <code class="literal">&quot;local&quot;</code> read concern, does not contact the
       shard&#039;s primary nor the config servers for updated metadata.
      </p>
     </dd>
    

    
     <dt id="mongodb-driver-readconcern.constants.linearizable"><strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.linearizable">MongoDB\Driver\ReadConcern::LINEARIZABLE</a></code></strong></dt>
     <dd>
      <p class="para">
       The query returns data that reflects all successful writes issued with a
       write concern of <code class="literal">&quot;majority&quot;</code> <em>and</em>
       acknowledged prior to the start of the read operation. For replica sets
       that run with <code class="literal">writeConcernMajorityJournalDefault</code> set
       to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>, linearizable read concern returns data that will never be
       rolled back.
      </p>
      <p class="para">
       With <code class="literal">writeConcernMajorityJournalDefault</code> set to
       <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>, MongoDB will not wait for <code class="literal">w: &quot;majority&quot;</code>
       writes to be durable before acknowledging the writes. As such,
       <code class="literal">&quot;majority&quot;</code> write operations could possibly roll back
       in the event of a loss of a replica set member.
      </p>
      <p class="para">
       You can specify linearizable read concern for read operations on the
       primary only.
      </p>
      <p class="para">
       Linearizable read concern guarantees only apply if read
       operations specify a query filter that uniquely identifies a single
       document.
      </p>
      <div class="tip"><strong class="tip">Tip</strong>
       <p class="simpara">
        Always use <code class="literal">maxTimeMS</code> with linearizable read concern
        in case a majority of data bearing members are unavailable.
        <code class="literal">maxTimeMS</code> ensures that the operation does not block
        indefinitely and instead ensures that the operation returns an error if
        the read concern cannot be fulfilled.
       </p>
      </div>
      <p class="para">
       Linearizable read concern requires MongoDB 3.4.
      </p>
     </dd>
    

    
     <dt id="mongodb-driver-readconcern.constants.local"><strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.local">MongoDB\Driver\ReadConcern::LOCAL</a></code></strong></dt>
     <dd>
      <p class="para">
       Default for reads against primary if <code class="literal">level</code> is
       unspecified and for reads against secondaries if <code class="literal">level</code>
       is unspecified but <code class="literal">afterClusterTime</code> is specified.
      </p>
      <p class="para">
       The query returns the instance&#039;s most recent data. Provides no
       guarantee that the data has been written to a majority of the replica set
       members (i.e. may be rolled back).
      </p>
     </dd>
    

    
     <dt id="mongodb-driver-readconcern.constants.majority"><strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.majority">MongoDB\Driver\ReadConcern::MAJORITY</a></code></strong></dt>
     <dd>
      <p class="para">
       The query returns the instance&#039;s most recent data acknowledged as
       having been written to a majority of members in the replica set.
      </p>
      <p class="para">
       To use read concern level of <code class="literal">&quot;majority&quot;</code>, replica sets
       must use WiredTiger storage engine and election protocol version 1.
      </p>
     </dd>
    

    
     <dt id="mongodb-driver-readconcern.constants.snapshot"><strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.snapshot">MongoDB\Driver\ReadConcern::SNAPSHOT</a></code></strong></dt>
     <dd>
      <p class="para">
       Read concern <code class="literal">&quot;snapshot&quot;</code> is available for
       multi-document transactions, and starting in MongoDB 5.0, certain read
       operations outside of multi-document transactions.
      </p>
      <p class="para">
       If the transaction is not part of a causally consistent session, upon
       transaction commit with write concern <code class="literal">&quot;majority&quot;</code>, the
       transaction operations are guaranteed to have read from a snapshot of
       majority-committed data.
      </p>
      <p class="para">
       If the transaction is part of a causally consistent session, upon
       transaction commit with write concern <code class="literal">&quot;majority&quot;</code>, the
       transaction operations are guaranteed to have read from a snapshot of
       majority-committed data that provides causal consistency with the
       operation immediately preceding the transaction start.
      </p>
      <p class="para">
       Outside of multi-document transactions, read concern
       <code class="literal">&quot;snapshot&quot;</code> is available on primaries and secondaries
       for the following read operations: <code class="literal">find</code>,
       <code class="literal">aggregate</code>, and <code class="literal">distinct</code> (on
       unsharded collections). All other read commands prohibit
       <code class="literal">&quot;snapshot&quot;</code>.
      </p>
     </dd>
    

   </dl>
  </div>


  <div class="section">
   <h2 class="title">Changelog</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>Version</th>
        <th>Description</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL mongodb 1.11.0</td>
        <td>
         <p class="para">
          Added the <strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.snapshot">MongoDB\Driver\ReadConcern::SNAPSHOT</a></code></strong>
          constant.
         </p>
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.7.0</td>
        <td>
         Implements <span class="interfacename"><a href="class.serializable.php" class="interfacename">Serializable</a></span>.
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.4.0</td>
        <td>
         <p class="para">
          Added the <strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.available">MongoDB\Driver\ReadConcern::AVAILABLE</a></code></strong>
          constant.
         </p>
        </td>
       </tr>

       <tr>
        <td>PECL mongodb 1.2.0</td>
        <td>
         <p class="para">
          Added the
          <strong><code><a href="class.mongodb-driver-readconcern.php#mongodb-driver-readconcern.constants.linearizable">MongoDB\Driver\ReadConcern::LINEARIZABLE</a></code></strong>
          constant.
         </p>
         <p class="para">
          Implements <span class="interfacename"><a href="class.mongodb-bson-serializable.php" class="interfacename">MongoDB\BSON\Serializable</a></span>.
         </p>
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

  <div class="section" id="mongodb-driver-readconcern.seealso">
   <h2 class="title">See Also</h2>
  <ul class="simplelist">
   <li><a href="https://www.mongodb.com/docs/manual/reference/read-concern/" class="link external">&raquo;&nbsp;Read Concern reference</a></li>
  </ul>
  </div>

 </div>

 




























<h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="mongodb-driver-readconcern.bsonserialize.php">MongoDB\Driver\ReadConcern::bsonSerialize</a> — Returns an object for BSON serialization</li><li><a href="mongodb-driver-readconcern.construct.php">MongoDB\Driver\ReadConcern::__construct</a> — Create a new ReadConcern</li><li><a href="mongodb-driver-readconcern.getlevel.php">MongoDB\Driver\ReadConcern::getLevel</a> — Returns the ReadConcern's &quot;level&quot; option</li><li><a href="mongodb-driver-readconcern.isdefault.php">MongoDB\Driver\ReadConcern::isDefault</a> — Checks if this is the default read concern</li></ul>
</div>
<?php manual_footer($setup); ?>