MongoDB C++ Driver mongocxx-3.4.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
mongocxx::read_concern Class Reference

A class to represent the read concern. More...

#include <read_concern.hpp>

Public Types

enum class  level
 A class to represent the read concern level. More...
 

Public Member Functions

 read_concern ()
 Constructs a new read_concern with default acknowledge_level of k_server_default.
 
 read_concern (const read_concern &)
 Copy constructs a read_concern.
 
read_concernoperator= (const read_concern &)
 Copy assigns a read_concern.
 
 read_concern (read_concern &&) noexcept
 Move constructs a read_concern.
 
read_concernoperator= (read_concern &&) noexcept
 Move assigns a read_concern.
 
 ~read_concern ()
 Destroys a read_concern.
 
void acknowledge_level (level rc_level)
 Sets the read concern level.
 
level acknowledge_level () const
 Gets the current read concern level.
 
void acknowledge_string (stdx::string_view rc_string)
 Sets the read concern string.
 
stdx::string_view acknowledge_string () const
 Gets the current read concern string.
 

Detailed Description

A class to represent the read concern.

Read concern can be set at the client, database, or collection level. The read concern can also be provided via connection string, and will be parsed and set on the client constructed for the URI.

For the WiredTiger storage engine, MongoDB 3.2 introduced the readConcern option for replica sets and replica set shards. The readConcern option allows clients to choose a level of isolation for their reads. You can specify a readConcern of "majority" to read data that has been written to a majority of nodes and thus cannot be rolled back. By default, MongoDB uses a readConcern of "local" which does not guarantee that the read data would not be rolled back.

MongoDB 3.4 introduces a read concern level of "linearizable" to read data that has been written to a majority of nodes (i.e. cannot be rolled back) and is not stale. Linearizable read concern is available for all MongoDB supported storage engines and applies to read operations on a single document. Note that writes must be made with majority write concern in order for reads to be linearizable.

See also
https://docs.mongodb.com/master/reference/read-concern/

Member Enumeration Documentation

◆ level

enum class mongocxx::read_concern::level
strong

A class to represent the read concern level.

See also
https://docs.mongodb.com/master/reference/read-concern/#read-concern-levels

Constructor & Destructor Documentation

◆ read_concern()

mongocxx::read_concern::read_concern ( )

Constructs a new read_concern with default acknowledge_level of k_server_default.

The k_server_default acknowledge level has an empty acknowledge_string. Queries that run with this read_concern will use the server's default read_concern instead of specifying one.

Member Function Documentation

◆ acknowledge_level() [1/2]

level mongocxx::read_concern::acknowledge_level ( ) const

Gets the current read concern level.

If this was set with acknowledge_string to anything other than "local", "majority", "linearizable", or an empty string, this will return k_unknown.

Returns
The read concern level.

◆ acknowledge_level() [2/2]

void mongocxx::read_concern::acknowledge_level ( level  rc_level)

Sets the read concern level.

Parameters
rc_levelEither k_local, k_majority, k_linearizable, or k_server_default.
Exceptions
mongocxx::exceptionif rc_level is not k_local, k_majority, k_linearizable, or k_server_default.

◆ acknowledge_string() [1/2]

stdx::string_view mongocxx::read_concern::acknowledge_string ( ) const

Gets the current read concern string.

If the read concern level was set with acknowledge_level, this will return either "local", "majority", "linearizable", or an empty string for k_server_default.

Returns
The read concern string.

◆ acknowledge_string() [2/2]

void mongocxx::read_concern::acknowledge_string ( stdx::string_view  rc_string)

Sets the read concern string.

Any valid read concern string (e.g. "local", "majority", "linearizable", "") may be passed in. For forward-compatibility with read concern levels introduced in the future, no validation is performed on this string.

Parameters
rc_stringThe read concern string.

The documentation for this class was generated from the following file: