Loading...
Searching...
No Matches
mongocxx::v_noabi::write_concern Class Reference

`#include <mongocxx/v_noabi/mongocxx/write_concern.hpp>`

## Description

The level of acknowledgment requested for write operations to a MongoDB server.

See also
  - Write Concern (MongoDB Manual)

## Public Types

enum class | level
| A class to represent the write concern level for write operations. More...

## Public Member Functions

| write_concern ()=default
| Constructs a new write_concern.
| write_concern (v1::write_concern rc)
| Construct with the mongocxx::v1 equivalent.
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.
bsoncxx::v_noabi::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.
| operator v1::write_concern () &&
| Convert to the mongocxx::v1 equivalent.
| operator v1::write_concern () const &
| Convert to the mongocxx::v1 equivalent.
bsoncxx::v_noabi::stdx::optional< std::string > | tag () const
| Gets the current getLastErrorMode that is required by this write_concern.
void | tag (bsoncxx::v_noabi::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== (write_concern const &lhs, write_concern const &rhs)
| Compares two write_concern objects for (in)-equality.
bool | operator!= (write_concern const &lhs, write_concern const &rhs)
| Compares two write_concern objects for (in)-equality.

## Member Enumeration Documentation

## level

enum class mongocxx::v_noabi::write_concern::level

strong

A class to represent the write concern level for write operations.

See also
  - Write Concern (MongoDB Manual)
  - Default MongoDB Read Concerns/Write Concerns

Enumerator
k_default | Represent the implicit default write concern.
k_majority | Represent write concern with w: "majority".
k_tag | Represent write concern with w: <custom write concern name>.
k_unacknowledged | Represent write concern with w: 0.
k_acknowledged | Represent write concern with w: 1.

## Constructor & Destructor Documentation

## write_concern() [1/2]

mongocxx::v_noabi::write_concern::write_concern | ( |  | ) |

default

Constructs a new write_concern.

## write_concern() [2/2]

mongocxx::v_noabi::write_concern::write_concern | ( | v1::write_concern | rc | ) |

inline

Construct with the mongocxx::v1 equivalent.

## Member Function Documentation

## acknowledge_level() [1/2]

level mongocxx::v_noabi::write_concern::acknowledge_level | ( |  | ) | const

inline

Gets the current acknowledgment level.

See also
  - https://www.mongodb.com/docs/manual/reference/write-concern/#w-option

Returns
  The acknowledgment level.

## acknowledge_level() [2/2]

void mongocxx::v_noabi::write_concern::acknowledge_level | ( | level | confirm_level | ) |

Sets the acknowledge level.

See also
  - https://www.mongodb.com/docs/manual/reference/write-concern/#w-option

Parameters

  confirm_level | Either level::k_unacknowledged, level::k_acknowledged, level::k_default, or level::k_majority.

Note
  the acknowledge level of level::k_tag is set automatically when a tag is set.

Warning
  Setting this to level::k_unacknowledged disables write acknowledgment and all other write concern options.
  Unacknowledged writes using dollar-prefixed or dotted keys may be silently rejected by pre-5.0 servers.

Exceptions

  Throws | mongocxx::v_noabi::exception for setting a tag acknowledge level. Use tag() instead.

## is_acknowledged()

bool mongocxx::v_noabi::write_concern::is_acknowledged | ( |  | ) | const

inline

Gets whether this write_concern requires an acknowledged write.

Returns
  Whether this write concern requires an acknowledged write.

## journal() [1/2]

bool mongocxx::v_noabi::write_concern::journal | ( |  | ) | const

inline

Gets the current status of the journal parameter.

Returns
  `true` if journal is required, `false` if not.

## journal() [2/2]

void mongocxx::v_noabi::write_concern::journal | ( | bool | journal | ) |

inline

Sets the journal parameter for this write concern.

Parameters

  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.

## majority() [1/2]

bool mongocxx::v_noabi::write_concern::majority | ( |  | ) | const

inline

Gets whether the majority of nodes is currently required by this write_concern.

Returns
  The current majority setting.

## majority() [2/2]

void mongocxx::v_noabi::write_concern::majority | ( | std::chrono::milliseconds | timeout | ) |

inline

Requires that a majority of the nodes in a replica set acknowledge a write operation before it is considered a success.

Parameters

  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.

Exceptions

  mongocxx::v_noabi::logic_error | for an invalid timeout value.

## nodes() [1/2]

bsoncxx::v_noabi::stdx::optional< std::int32_t > mongocxx::v_noabi::write_concern::nodes | ( |  | ) | const

inline

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.

See also
  - https://www.mongodb.com/docs/manual/reference/write-concern/#w-option

Returns
  The number of required nodes.

## nodes() [2/2]

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.

Parameters

  confirm_from | The number of replica set nodes that must acknowledge the write.

Warning
  Setting the number of nodes to 0 disables write acknowledgment and all other write concern options.
  Setting the number of nodes required to an amount greater than the number of available nodes will cause writes using this write concern to block forever if no timeout is set.

## operator v1::write_concern() [1/2]

mongocxx::v_noabi::write_concern::operator v1::write_concern | ( |  | ) | &&

inline explicit

Convert to the mongocxx::v1 equivalent.

Postconditions:
  - *this is in an assign-or-destroy-only state.

Warning
  Invalidates all associated views.

## operator v1::write_concern() [2/2]

mongocxx::v_noabi::write_concern::operator v1::write_concern | ( |  | ) | const &

inline explicit

Convert to the mongocxx::v1 equivalent.

## tag() [1/2]

bsoncxx::v_noabi::stdx::optional< std::string > mongocxx::v_noabi::write_concern::tag | ( |  | ) | const

inline

Gets the current getLastErrorMode that is required by this write_concern.

Returns
  The current getLastErrorMode.

## tag() [2/2]

void mongocxx::v_noabi::write_concern::tag | ( | bsoncxx::v_noabi::stdx::string_view | tag | ) |

inline

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.

Note
  the acknowledge level of level::k_tag is set automatically when a tag is set.

Parameters

  tag | The string representing on of the "getLastErrorModes" in the replica set configuration.

## timeout() [1/2]

std::chrono::milliseconds mongocxx::v_noabi::write_concern::timeout | ( |  | ) | const

inline

Gets the current timeout for this write_concern.

Returns
  Current timeout in milliseconds.

## timeout() [2/2]

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.

Parameters

  timeout | The timeout (in milliseconds) for this write concern. If the value is zero, then no timeout is set.

Exceptions

  mongocxx::v_noabi::logic_error | for an invalid timeout value.

## to_document()

bsoncxx::v_noabi::document::value mongocxx::v_noabi::write_concern::to_document | ( |  | ) | const

inline

Gets the document form of this write_concern.

Returns
  Document representation of this write_concern.

## Friends And Related Symbol Documentation

## operator!=

bool operator!= | ( | write_concern const & | lhs,
|  | write_concern const & | rhs )

friend

Compares two write_concern objects for (in)-equality.

## operator==

bool operator== | ( | write_concern const & | lhs,
|  | write_concern const & | rhs )

friend

Compares two write_concern objects for (in)-equality.

The documentation for this class was generated from the following file:

- mongocxx/v_noabi/mongocxx/write_concern.hpp