MongoDB C++ Driver  legacy-1.1.2
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. 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...
 
WriteConcernnodes (int w)
 Sets the number of nodes required for write to be successful. More...
 
WriteConcernmode (const StringData &w)
 Sets the type of nodes required for write to be successful. More...
 
WriteConcernjournal (bool j)
 Sets whether journal is required for write to be successful. More...
 
WriteConcernfsync (bool fsync)
 Sets the value of the fsync parameter. More...
 
WriteConcerntimeout (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)
 

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

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.
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.
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
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.

Returns
nodes required as std::string
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.

Returns
number of nodes required
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.

Returns
int representing milliseconds to wait for write
WriteConcern& mongo::WriteConcern::timeout ( int  timeout)

Sets timeout to wait for write to be successful.

Member Data Documentation

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: