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

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

## Description

Options related to a MongoDB Write Concern.

Supported fields include:

- journal ("j")
- level ("w")
- timeout ("wtimeout")

See also
  - Write Concern (MongoDB Manual)

## Public Types

enum class | level
| The write concern level. More...

## Public Member Functions

| write_concern ()
| Default initialization.
| write_concern (write_concern &&other) noexcept
| Move constructor.
| write_concern (write_concern const &other)
| Copy construction.
| ~write_concern ()
| Destroy this object.
level | acknowledge_level () const
| Return the current "w" field as an acknowledgement level.
write_concern & | acknowledge_level (level v)
| Set the "w" field as to acknowledgement level.
bool | is_acknowledged () const
| Return true when this write concern requires acknowledgement.
bsoncxx::v1::stdx::optional< bool > | journal () const
| Return the current "j" field.
write_concern & | journal (bool j)
| Set the "j" field.
write_concern & | majority ()
| Equivalent to this->acknowledge_level(level::k_majority).
write_concern & | majority (std::chrono::milliseconds v)
| Equivalent to this->acknowledge_level(k_majority).timeout(timeout).
bsoncxx::v1::stdx::optional< std::int32_t > | nodes () const
| Return the current "w" field as an integer.
write_concern & | nodes (std::int32_t v)
| Set the "w" field to an integer.
write_concern & | operator= (write_concern &&other) noexcept
| Move assignment.
write_concern & | operator= (write_concern const &other)
| Copy assignment.
bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > | tag () const
| Return the current "w" value as a custom write concern name.
write_concern & | tag (bsoncxx::v1::stdx::string_view v)
| Set the "w" field to a custom write concern name.
std::chrono::milliseconds | timeout () const
| Return the current "wtimeout" field.
write_concern & | timeout (std::chrono::milliseconds v)
| Set the "wtimeout" field.
bsoncxx::v1::document::value | to_document () const
| Return this write concern option as a document.

## Friends

bool | operator== (write_concern const &lhs, write_concern const &rhs)
| Compare equal when all supported fields compare equal.
bool | operator!= (write_concern const &lhs, write_concern const &rhs)
| Compare equal when all supported fields compare equal.

## Member Enumeration Documentation

## level

enum class mongocxx::v1::write_concern::level

strong

The write concern level.

See also
  - Write Concern (MongoDB Manual)

Enumerator
k_default | Default MongoDB Read Concerns/Write Concerns (MongoDB Manual)
k_majority | "w": "majority"
k_tag | "w": "<custom write concern name>"
k_unacknowledged | "w": 0
k_acknowledged | "w": 1

k_unknown

An unknown (unsupported) write concern level.

Note
  Not to be confused with level::k_default.

## Constructor & Destructor Documentation

## ~write_concern()

mongocxx::v1::write_concern::~write_concern | ( |  | ) |

Destroy this object.

## write_concern() [1/3]

mongocxx::v1::write_concern::write_concern | ( | write_concern && | other | ) |

noexcept

Move constructor.

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

## write_concern() [2/3]

mongocxx::v1::write_concern::write_concern | ( | write_concern const & | other | ) |

Copy construction.

## write_concern() [3/3]

mongocxx::v1::write_concern::write_concern | ( |  | ) |

Default initialization.

Postconditions:
  - All supported fields are "unset" or zero-initialized.

## Member Function Documentation

## acknowledge_level() [1/2]

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

Return the current "w" field as an acknowledgement level.

Returns
  - level::k_default when "w" is unset.
  - level::k_majority when "w": "majority".
  - level::k_tag when "w": <custom write concern name>.
  - level::k_unacknowledged when "w": 0.
  - level::k_acknowledged when "w": n and n >= 1.
  - level::k_unknown for all other (unsupported) values.

## acknowledge_level() [2/2]

write_concern & mongocxx::v1::write_concern::acknowledge_level | ( | level | v | ) |

Set the "w" field as to acknowledgement level.

Parameters

  v

  One of:
  - k_default
  - k_majority
  - k_unacknowledged
  - k_acknowledged

## is_acknowledged()

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

Return true when this write concern requires acknowledgement.

## journal() [1/2]

bsoncxx::v1::stdx::optional< bool > mongocxx::v1::write_concern::journal | ( |  | ) | const

Return the current "j" field.

## journal() [2/2]

write_concern & mongocxx::v1::write_concern::journal | ( | bool | j | ) |

Set the "j" field.

## majority() [1/2]

write_concern & mongocxx::v1::write_concern::majority | ( |  | ) |

inline

Equivalent to this->acknowledge_level(level::k_majority).

## majority() [2/2]

write_concern & mongocxx::v1::write_concern::majority | ( | std::chrono::milliseconds | v | ) |

inline

Equivalent to this->acknowledge_level(k_majority).timeout(timeout).

## nodes() [1/2]

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

Return the current "w" field as an integer.

Returns
  Empty when this->acknowledge_level() is not level::k_unacknowledged or level::k_acknowledged.

## nodes() [2/2]

write_concern & mongocxx::v1::write_concern::nodes | ( | std::int32_t | v | ) |

Set the "w" field to an integer.

Parameters

  v

  - 0 is equivalent to this->acknowledge_level(k_unacknowledged).
  - 1 is equivalent to this->acknowledge_level(k_acknowledged).

## operator=() [1/2]

write_concern & mongocxx::v1::write_concern::operator= | ( | write_concern && | other | ) |

noexcept

Move assignment.

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

## operator=() [2/2]

write_concern & mongocxx::v1::write_concern::operator= | ( | write_concern const & | other | ) |

Copy assignment.

## tag() [1/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::stdx::string_view > mongocxx::v1::write_concern::tag | ( |  | ) | const

Return the current "w" value as a custom write concern name.

Returns
  Empty when this->acknowledge_level() is not level::k_tag.

## tag() [2/2]

write_concern & mongocxx::v1::write_concern::tag | ( | bsoncxx::v1::stdx::string_view | v | ) |

Set the "w" field to a custom write concern name.

## timeout() [1/2]

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

Return the current "wtimeout" field.

Note
  0 is equivalent to "unset".

## timeout() [2/2]

write_concern & mongocxx::v1::write_concern::timeout | ( | std::chrono::milliseconds | v | ) |

Set the "wtimeout" field.

Note
  0 is equivalent to "unset".

## to_document()

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

Return this write concern option as a document.

Preconditions:
  - this->acknowledge_level() != level::k_unknown.

## Friends And Related Symbol Documentation

## operator!=

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

friend

Compare equal when all supported fields compare equal.

## operator==

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

friend

Compare equal when all supported fields compare equal.

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

- mongocxx/v1/write_concern.hpp