MongoDB C++ Driver
legacy-1.1.2
|
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. More... | |
const std::string & | mode () const |
Returns a string representing the write concern mode. More... | |
bool | journal () const |
If write will only be considered successful when committed to journal. More... | |
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. More... | |
int32_t | timeout () const |
Length of time to block waiting for nodes, journal, or fsync. More... | |
WriteConcern & | nodes (int w) |
Sets the number of nodes required for write to be successful. More... | |
WriteConcern & | mode (const StringData &w) |
Sets the type of nodes required for write to be successful. More... | |
WriteConcern & | journal (bool j) |
Sets whether journal is required for write to be successful. More... | |
WriteConcern & | fsync (bool fsync) |
Sets the value of the fsync parameter. More... | |
WriteConcern & | timeout (int timeout) |
Sets timeout to wait for write to be successful. More... | |
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. More... | |
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 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).
WriteConcern& mongo::WriteConcern::fsync | ( | bool | fsync | ) |
Sets the value of the fsync parameter.
bool mongo::WriteConcern::journal | ( | ) | const |
If write will only be considered successful when committed to journal.
WriteConcern& mongo::WriteConcern::journal | ( | bool | j | ) |
Sets whether journal is required for write to be successful.
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.
WriteConcern& mongo::WriteConcern::mode | ( | const StringData & | w | ) |
Sets the type of nodes required for write to be successful.
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.
WriteConcern& mongo::WriteConcern::nodes | ( | int | w | ) |
Sets the number of nodes required for write to be successful.
int32_t mongo::WriteConcern::timeout | ( | ) | const |
Length of time to block waiting for nodes, journal, or fsync.
WriteConcern& mongo::WriteConcern::timeout | ( | int | timeout | ) |
Sets timeout to wait for write to be successful.
|
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.