MongoDB C++ Driver mongocxx-3.11.0
|
#include <mongocxx/v_noabi/mongocxx/write_concern.hpp>
Class representing the server-side requirement for reporting the success of a write operation. The strength of the write concern setting determines the level of guarantees that you will receive from MongoDB regarding write durability.
Weaker requirements that provide fewer guarantees report on success quickly while stronger requirements that provide greater guarantees will take longer (or potentially forever, if the write_concern's requirements are not satisfied and no timeout is set).
MongoDB drivers allow for different levels of write concern to better address the specific needs of applications. Clients may adjust write concern to ensure that the most important operations persist successfully to an entire MongoDB deployment. However, for other less critical operations, clients can adjust the write concern to ensure better performance rather than persistence to the entire deployment.
Public Types | |
enum class | level |
A class to represent the write concern level for write operations. More... | |
Public Member Functions | |
write_concern () | |
Constructs a new write_concern. | |
write_concern (const write_concern &) | |
Copy constructs a write_concern. | |
write_concern (write_concern &&) noexcept | |
Move constructs a write_concern. | |
~write_concern () | |
Destroys a write_concern. | |
level | acknowledge_level () const |
Gets the current acknowledgment level. | |
void | acknowledge_level (level confirm_level) |
Sets the acknowledge level. | |
bool | is_acknowledged () const |
Gets whether this write_concern requires an acknowledged write. | |
bool | journal () const |
Gets the current status of the journal parameter. | |
void | journal (bool journal) |
Sets the journal parameter for this write concern. | |
bool | majority () const |
Gets whether the majority of nodes is currently required by this write_concern. | |
void | majority (std::chrono::milliseconds timeout) |
Requires that a majority of the nodes in a replica set acknowledge a write operation before it is considered a success. | |
stdx::optional< std::int32_t > | nodes () const |
Gets the current number of nodes that this write_concern requires operations to reach. This value will be unset if the acknowledge_level is set to majority, default, or tag. | |
void | nodes (std::int32_t confirm_from) |
Sets the number of nodes that are required to acknowledge the write before the operation is considered successful. Write operations will block until they have been replicated to the specified number of servers in a replica set. | |
write_concern & | operator= (const write_concern &) |
Copy assigns a write_concern. | |
write_concern & | operator= (write_concern &&) noexcept |
Move assigns a write_concern. | |
stdx::optional< std::string > | tag () const |
Gets the current getLastErrorMode that is required by this write_concern. | |
void | tag (stdx::string_view tag) |
Sets the name representing the server-side getLastErrorMode entry containing the list of nodes that must acknowledge a write operation before it is considered a success. | |
std::chrono::milliseconds | timeout () const |
Gets the current timeout for this write_concern. | |
void | timeout (std::chrono::milliseconds timeout) |
Sets an upper bound on the time a write concern can take to be satisfied. If the write concern cannot be satisfied within the timeout, the operation is considered a failure. | |
bsoncxx::v_noabi::document::value | to_document () const |
Gets the document form of this write_concern. | |
Related Symbols | |
(Note that these are not member symbols.) | |
bool | operator== (const write_concern &, const write_concern &) |
Compares two write_concern objects for (in)-equality. | |
bool | operator!= (const write_concern &, const write_concern &) |
Compares two write_concern objects for (in)-equality. | |
|
strong |
A class to represent the write concern level for write operations.
mongocxx::v_noabi::write_concern::write_concern | ( | ) |
Constructs a new write_concern.
mongocxx::v_noabi::write_concern::write_concern | ( | const write_concern & | ) |
Copy constructs a write_concern.
|
noexcept |
Move constructs a write_concern.
mongocxx::v_noabi::write_concern::~write_concern | ( | ) |
Destroys a write_concern.
level mongocxx::v_noabi::write_concern::acknowledge_level | ( | ) | const |
Gets the current acknowledgment level.
void mongocxx::v_noabi::write_concern::acknowledge_level | ( | level | confirm_level | ) |
Sets the acknowledge level.
confirm_level | Either level::k_unacknowledged, level::k_acknowledged, level::k_default, or level::k_majority. |
Throws | mongocxx::v_noabi::exception for setting a tag acknowledge level. Use tag() instead. |
bool mongocxx::v_noabi::write_concern::is_acknowledged | ( | ) | const |
Gets whether this write_concern requires an acknowledged write.
bool mongocxx::v_noabi::write_concern::journal | ( | ) | const |
Gets the current status of the journal parameter.
true
if journal is required, false
if not. void mongocxx::v_noabi::write_concern::journal | ( | bool | journal | ) |
Sets the journal parameter for this write concern.
journal | If true confirms that the mongod instance has written the data to the on-disk journal before reporting a write operations was successful. This ensures that data is not lost if the mongod instance shuts down unexpectedly. |
bool mongocxx::v_noabi::write_concern::majority | ( | ) | const |
Gets whether the majority of nodes is currently required by this write_concern.
void mongocxx::v_noabi::write_concern::majority | ( | std::chrono::milliseconds | timeout | ) |
Requires that a majority of the nodes in a replica set acknowledge a write operation before it is considered a success.
timeout | The amount of time to wait before the write operation times out if it cannot reach the majority of nodes in the replica set. If the value is zero, then no timeout is set. |
mongocxx::v_noabi::logic_error | for an invalid timeout value. |
stdx::optional< std::int32_t > mongocxx::v_noabi::write_concern::nodes | ( | ) | const |
Gets the current number of nodes that this write_concern requires operations to reach. This value will be unset if the acknowledge_level is set to majority, default, or tag.
This is unset by default.
void mongocxx::v_noabi::write_concern::nodes | ( | std::int32_t | confirm_from | ) |
Sets the number of nodes that are required to acknowledge the write before the operation is considered successful. Write operations will block until they have been replicated to the specified number of servers in a replica set.
confirm_from | The number of replica set nodes that must acknowledge the write. |
write_concern & mongocxx::v_noabi::write_concern::operator= | ( | const write_concern & | ) |
Copy assigns a write_concern.
|
noexcept |
Move assigns a write_concern.
stdx::optional< std::string > mongocxx::v_noabi::write_concern::tag | ( | ) | const |
Gets the current getLastErrorMode that is required by this write_concern.
void mongocxx::v_noabi::write_concern::tag | ( | stdx::string_view | tag | ) |
Sets the name representing the server-side getLastErrorMode entry containing the list of nodes that must acknowledge a write operation before it is considered a success.
tag | The string representing on of the "getLastErrorModes" in the replica set configuration. |
std::chrono::milliseconds mongocxx::v_noabi::write_concern::timeout | ( | ) | const |
Gets the current timeout for this write_concern.
void mongocxx::v_noabi::write_concern::timeout | ( | std::chrono::milliseconds | timeout | ) |
Sets an upper bound on the time a write concern can take to be satisfied. If the write concern cannot be satisfied within the timeout, the operation is considered a failure.
timeout | The timeout (in milliseconds) for this write concern. If the value is zero, then no timeout is set. |
mongocxx::v_noabi::logic_error | for an invalid timeout value. |
bsoncxx::v_noabi::document::value mongocxx::v_noabi::write_concern::to_document | ( | ) | const |
Gets the document form of this write_concern.
|
friend |
Compares two write_concern objects for (in)-equality.
|
friend |
Compares two write_concern objects for (in)-equality.