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

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

## Description

Options related to a MongoDB Read Preference.

Supported fields include:

- hedge
- max_staleness ("maxStalenessSeconds")
- mode
- tags ("tag_sets")

See also
  - Read Preference (MongoDB Manual)

## Public Types

enum class | read_mode
| The read preference mode. More...

## Public Member Functions

| read_preference ()
| Default initialization.
| read_preference (read_preference &&other) noexcept
| Move constructor.
| read_preference (read_preference const &other)
| Copy construction.
| ~read_preference ()
| Destroy this object.
bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > | hedge () const
| Return the current "hedge" field.
read_preference & | hedge (bsoncxx::v1::document::view v)
| Set the "hedge" field.
bsoncxx::v1::stdx::optional< std::chrono::seconds > | max_staleness () const
| Return the current "maxStalenessSeconds" field.
read_preference & | max_staleness (std::chrono::seconds v)
| Set the "maxStalenessSeconds" field.
read_mode | mode () const
| Return the current "mode" field.
read_preference & | mode (read_mode v)
| Set the "mode" field.
read_preference & | operator= (read_preference &&other) noexcept
| Move assignment.
read_preference & | operator= (read_preference const &other)
| Copy assignment.
bsoncxx::v1::array::view | tags () const
| Return the current "tag_sets" field.
read_preference & | tags (bsoncxx::v1::array::view v)
| Set the "tag_sets" field.
read_preference & | tags (bsoncxx::v1::document::view v)
| Set the "tag_sets" field.

## Friends

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

## Member Enumeration Documentation

## read_mode

enum class mongocxx::v1::read_preference::read_mode

strong

The read preference mode.

See also
  - Read Preference (MongoDB Manual)

Enumerator
k_primary | Primary member only (default).
k_primary_preferred | Primary member when available, secondary otherwise.
k_secondary | Secondary members only.
k_secondary_preferred | Secondary members when available, primary otherwise.
k_nearest | A random eligible member based on a specified latency threshold.

## Constructor & Destructor Documentation

## ~read_preference()

mongocxx::v1::read_preference::~read_preference | ( |  | ) |

Destroy this object.

## read_preference() [1/3]

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

noexcept

Move constructor.

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

## read_preference() [2/3]

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

Copy construction.

## read_preference() [3/3]

mongocxx::v1::read_preference::read_preference | ( |  | ) |

Default initialization.

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

## Member Function Documentation

## hedge() [1/2]

bsoncxx::v1::stdx::optional< bsoncxx::v1::document::view > mongocxx::v1::read_preference::hedge | ( |  | ) | const

Return the current "hedge" field.

Deprecated
  Deprecated in MongoDB Server version 8.0.

## hedge() [2/2]

read_preference & mongocxx::v1::read_preference::hedge | ( | bsoncxx::v1::document::view | v | ) |

Set the "hedge" field.

Deprecated
  Deprecated in MongoDB Server version 8.0.

## max_staleness() [1/2]

bsoncxx::v1::stdx::optional< std::chrono::seconds > mongocxx::v1::read_preference::max_staleness | ( |  | ) | const

Return the current "maxStalenessSeconds" field.

Returns
  An empty optional if the option is unset.

## max_staleness() [2/2]

read_preference & mongocxx::v1::read_preference::max_staleness | ( | std::chrono::seconds | v | ) |

Set the "maxStalenessSeconds" field.

Parameters

  v | -1 is equivalent to "unset".

## mode() [1/2]

read_mode mongocxx::v1::read_preference::mode | ( |  | ) | const

Return the current "mode" field.

## mode() [2/2]

read_preference & mongocxx::v1::read_preference::mode | ( | read_mode | v | ) |

Set the "mode" field.

Parameters

  v

  One of:
  - read_mode::k_primary
  - read_mode::k_primary_preferred
  - read_mode::k_secondary
  - read_mode::k_secondary_preferred
  - read_mode::k_nearest

See also
  - Read Preference Use Cases

## operator=() [1/2]

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

noexcept

Move assignment.

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

## operator=() [2/2]

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

Copy assignment.

## tags() [1/3]

bsoncxx::v1::array::view mongocxx::v1::read_preference::tags | ( |  | ) | const

Return the current "tag_sets" field.

## tags() [2/3]

read_preference & mongocxx::v1::read_preference::tags | ( | bsoncxx::v1::array::view | v | ) |

Set the "tag_sets" field.

## tags() [3/3]

read_preference & mongocxx::v1::read_preference::tags | ( | bsoncxx::v1::document::view | v | ) |

Set the "tag_sets" field.

## Friends And Related Symbol Documentation

## operator!=

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

friend

Compare equal when all supported fields compare equal.

## operator==

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

friend

Compare equal when all supported fields compare equal.

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

- mongocxx/v1/read_preference.hpp