MongoDB C++ Driver legacy-1.0.0
|
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. | |
WriteConcern & | nodes (int w) |
Sets the number of nodes required for write to be successful. | |
WriteConcern & | mode (const StringData &w) |
Sets the type of nodes required for write to be successful. | |
WriteConcern & | journal (bool j) |
Sets whether journal is required for write to be successful. | |
WriteConcern & | fsync (bool fsync) |
Sets whether fsync is required for write to be successful. | |
WriteConcern & | timeout (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) | |
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);
bool mongo::WriteConcern::fsync | ( | ) | const |
If write will only be considered successful when committed to data files.
bool mongo::WriteConcern::journal | ( | ) | const |
If write will only be considered successful when committed to journal.
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.
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.
int32_t mongo::WriteConcern::timeout | ( | ) | const |
Length of time to block waiting for nodes, journal, or fsync.
|
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.