MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
mongo::WriteConcern Class Reference

Class to encapsulate client side "Write Concern" concept. More...

#include <write_concern.h>

Public Member Functions

 WriteConcern ()
 Default write concern: equivalent to acknowledged.
 
int32_t nodes () const
 Returns an integer representing the number of nodes required for write to be considered successful.
 
const std::string & mode () const
 Returns a string representing the write concern mode.
 
bool journal () const
 If write will only be considered successful when committed to journal.
 
bool fsync () const
 If fsync is set and the server is running without journaling, the write will only be considered successful when the server has synced all data files to disk.
 
int32_t timeout () const
 Length of time to block waiting for nodes, journal, or fsync.
 
WriteConcernnodes (int w)
 Sets the number of nodes required for write to be successful.
 
WriteConcernmode (const StringData &w)
 Sets the type of nodes required for write to be successful.
 
WriteConcernjournal (bool j)
 Sets whether journal is required for write to be successful.
 
WriteConcernfsync (bool fsync)
 Sets the value of the fsync parameter.
 
WriteConcerntimeout (int timeout)
 Sets timeout to wait for write to be successful.
 
bool requiresConfirmation () const
 Whether we need to send getLastError for this WriteConcern.
 
bool hasMode () const
 Whether the write concern currently reflects a mode.
 
BSONObj obj () const
 Turn write concern into an object for inclusion in GetLastError or write command.
 

Static Public Attributes

static const char kMajority []
 Using nodes(kMajority) confirms that write operations have propagated to the majority of a replica set.
 
static const WriteConcern unacknowledged
 Fire and forget.
 
static const WriteConcern acknowledged
 A single node acknowledges the write, equivalent to default constructor.
 
static const WriteConcern journaled
 A single node acknowledges the write operation was committed to journal.
 
static const WriteConcern replicated
 Two nodes have acknowledged receipt of the write operation.
 
static const WriteConcern majority
 A majority of nodes acknowledges (replica set)
 

Detailed Description

Class to encapsulate client side "Write Concern" concept.

Write concern describes the guarantee that MongoDB provides when reporting on the success of a write operation.

Example usage: WriteConcern wc = WriteConcern().nodes(3).journal(false);

Member Function Documentation

◆ fsync() [1/2]

bool mongo::WriteConcern::fsync ( ) const

If fsync is set and the server is running without journaling, the write will only be considered successful when the server has synced all data files to disk.

If the server is running with journaling, this acts the same as if journal() was set. Cannot be used in combination with journal(true).

Returns
true if the fsync option is set on the write.

◆ fsync() [2/2]

WriteConcern & mongo::WriteConcern::fsync ( bool  fsync)

Sets the value of the fsync parameter.

Note
The behavior of this option is dependent on server configuration.
See also
The comment on fsync() for details.

◆ journal()

bool mongo::WriteConcern::journal ( ) const

If write will only be considered successful when committed to journal.

Returns
true if write will block on MongoDB journal

◆ mode()

const std::string & mongo::WriteConcern::mode ( ) const

Returns a string representing the write concern mode.

If set this becomes the "w" parameter when sent to the server.

Returns
nodes required as std::string

◆ nodes()

int32_t mongo::WriteConcern::nodes ( ) const

Returns an integer representing the number of nodes required for write to be considered successful.

If set this becomes the "w" parameter when sent to the server.

Returns
number of nodes required

◆ timeout()

int32_t mongo::WriteConcern::timeout ( ) const

Length of time to block waiting for nodes, journal, or fsync.

Returns
int representing milliseconds to wait for write

Member Data Documentation

◆ kMajority

const char mongo::WriteConcern::kMajority[]
static

Using nodes(kMajority) confirms that write operations have propagated to the majority of a replica set.

This allows you to avoid hard coding assumptions about the size of your replica set into your application.


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