#include <mongocxx/v_noabi/mongocxx/read_preference.hpp>
Describes how MongoDB clients route read operations to the members of a replica set or sharded cluster.
Public Types | |
| enum class | read_mode : std::uint8_t |
| Determines which members in a replica set are acceptable to read from. More... | |
Public Member Functions | |
| read_preference ()=default | |
| Constructs a new read_preference with read_mode set to k_primary. | |
| read_preference (read_mode mode) | |
| Constructs a new read_preference. | |
| read_preference (read_mode mode, bsoncxx::v_noabi::document::view_or_value tags) | |
| Constructs a new read_preference with tags. | |
| read_preference (v1::read_preference rp) | |
| Construct with the mongocxx::v1 equivalent. | |
| bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > const | hedge () const |
| Gets the current hedge document to be used for the read preference. | |
| read_preference & | hedge (bsoncxx::v_noabi::document::view_or_value hedge) |
| Sets the hedge document to be used for the read preference. Sharded clusters running MongoDB 4.4 or later can dispatch read operations in parallel, returning the result from the fastest host and cancelling the unfinished operations. | |
| bsoncxx::v_noabi::stdx::optional< std::chrono::seconds > | max_staleness () const |
| Returns the current max staleness setting for this read_preference. | |
| read_preference & | max_staleness (std::chrono::seconds max_staleness) |
| Sets the max staleness setting for this read_preference. Secondary servers with an estimated lag greater than this value will be excluded from selection under modes that allow secondaries. | |
| read_mode | mode () const |
| Returns the current read_mode for this read_preference. | |
| read_preference & | mode (read_mode mode) |
| Sets a new mode for this read_preference. | |
| operator v1::read_preference () && | |
| Convert to the mongocxx::v1 equivalent. | |
| operator v1::read_preference () const & | |
| Convert to the mongocxx::v1 equivalent. | |
| bsoncxx::v_noabi::stdx::optional< bsoncxx::v_noabi::document::view > | tags () const |
| Returns the current tag set list for this read_preference. | |
| read_preference & | tags (bsoncxx::v_noabi::array::view_or_value tag_set_list) |
| Sets or updates the tag set list for this read_preference. | |
| read_preference & | tags (bsoncxx::v_noabi::document::view_or_value tag_set_list) |
| Sets or updates the tag set list for this read_preference. | |
Related Symbols | |
(Note that these are not member symbols.) | |
| bool | operator== (read_preference const &lhs, read_preference const &rhs) |
| Compares two read_preference objects for (in)-equality. | |
| bool | operator!= (read_preference const &lhs, read_preference const &rhs) |
| Compares two read_preference objects for (in)-equality. | |
|
strong |
Determines which members in a replica set are acceptable to read from.
Constructs a new read_preference with read_mode set to k_primary.
Construct with the mongocxx::v1 equivalent.
|
inline |
Constructs a new read_preference.
| mode | Specifies the read_mode. |
|
inline |
Constructs a new read_preference with tags.
| mode | A read_preference read_mode. |
| tags | A document representing tags to use for the read_preference. |
|
inline |
Gets the current hedge document to be used for the read preference.
|
inline |
Sets the hedge document to be used for the read preference. Sharded clusters running MongoDB 4.4 or later can dispatch read operations in parallel, returning the result from the fastest host and cancelling the unfinished operations.
This may be an empty document or a document of the form { enabled: <boolean> }.
Hedged reads are automatically enabled in MongoDB 4.4+ when using a nearest read preference. To explicitly enable or disable hedging, the hedge document must be passed. An empty document uses server defaults to control hedging, but the enabled key may be set to true or false to explicitly enable or disable hedged reads.
| hedge | The hedge document to set. For example, the document { enabled: true }. |
|
inline |
Returns the current max staleness setting for this read_preference.
| read_preference & mongocxx::v_noabi::read_preference::max_staleness | ( | std::chrono::seconds | max_staleness | ) |
Sets the max staleness setting for this read_preference. Secondary servers with an estimated lag greater than this value will be excluded from selection under modes that allow secondaries.
Max staleness must be at least 90 seconds, and also at least the sum (in seconds) of the client's heartbeatFrequencyMS and the server's idle write period, which is 10 seconds. For general use, 90 seconds is the effective minimum. If less, an exception will be thrown when an operation is attempted.
Max staleness may only be used with MongoDB version 3.4 or later. If used with an earlier version, an exception will be thrown when an operation is attempted.
| max_staleness | The new max staleness setting. It must be positive. |
| mongocxx::v_noabi::logic_error | if the argument is invalid. |
|
inline |
Returns the current read_mode for this read_preference.
|
inline |
Sets a new mode for this read_preference.
| mode | The new read preference mode. |
|
inlineexplicit |
Convert to the mongocxx::v1 equivalent.
|
inlineexplicit |
Convert to the mongocxx::v1 equivalent.
|
inline |
Returns the current tag set list for this read_preference.
|
inline |
Sets or updates the tag set list for this read_preference.
| tag_set_list | Array of tag sets. |
|
inline |
Sets or updates the tag set list for this read_preference.
| tag_set_list | Document representing the tag set list. |
|
friend |
Compares two read_preference objects for (in)-equality.
|
friend |
Compares two read_preference objects for (in)-equality.