MongoDB C++ Driver legacy-1.0.0
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 write will only be considered successful when committed to data files.
 
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 whether fsync is required for write to be successful.
 
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()

bool mongo::WriteConcern::fsync ( ) const

If write will only be considered successful when committed to data files.

Returns
true if write will block on MongoDB fsync

◆ 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: