MongoDB C++ Driver mongocxx-3.0.3
|
Class representing a preference for how the driver routes read operations to members of a replica set or to a sharded cluster. More...
#include <read_preference.hpp>
Public Types | |
enum class | read_mode : std::uint8_t { k_primary = 0x01 , k_primary_preferred = 0x05 , k_secondary = 0x02 , k_secondary_preferred = 0x06 , k_nearest = 0x0A } |
Determines which members in a replica set are acceptable to read from. More... | |
Public Member Functions | |
read_preference (read_mode mode=read_mode::k_primary) | |
Constructs a new read_preference. | |
read_preference (read_mode mode, bsoncxx::document::view_or_value tags) | |
Constructs a new read_preference with tags. | |
read_preference (const read_preference &) | |
Copy constructs a read_preference. | |
read_preference & | operator= (const read_preference &) |
Copy assigns a read_preference. | |
read_preference (read_preference &&) noexcept | |
Move constructs a read_preference. | |
read_preference & | operator= (read_preference &&) noexcept |
Move assigns a read_preference. | |
~read_preference () | |
Destroys a read_preference. | |
void | mode (read_mode mode) |
Sets a new mode for this read_preference. | |
read_mode | mode () const |
Returns the current read_mode for this read_preference. | |
void | tags (bsoncxx::document::view_or_value tags) |
Sets or updates the tags for this read_preference. | |
stdx::optional< bsoncxx::document::view > | tags () const |
Returns the current tags for this read_preference. | |
Class representing a preference for how the driver routes read operations to members of a replica set or to a sharded cluster.
By default read operations are directed to the primary member in a replica set. Reading from the primary guarantees that read operations reflect the latest version of a document. However, by distributing some or all reads to secondary members of the replica set, you can improve read throughput or reduce latency for an application that does not require fully up-to-date data.
Read preference can be broadly specified by setting a mode. It is also possible to set tags in the read preference for more granular control, and to target specific members of a replica set via attributes other than their current state as a primary or secondary node.
Read preferences are ignored for direct connections to a single mongod instance. However, in order to perform read operations on a direct connection to a secondary member of a replica set, you must set a read preference that allows reading from secondaries.
|
strong |
Determines which members in a replica set are acceptable to read from.
|
explicit |
Constructs a new read_preference.
mode | Optional parameter to specify the read_mode, defaults to k_primary. |
mongocxx::read_preference::read_preference | ( | read_mode | mode, |
bsoncxx::document::view_or_value | tags | ||
) |
Constructs a new read_preference with tags.
mode | A read_preference read_mode. |
tags | A document representing tags to use for the read_preference. |
read_mode mongocxx::read_preference::mode | ( | ) | const |
Returns the current read_mode for this read_preference.
void mongocxx::read_preference::mode | ( | read_mode | mode | ) |
Sets a new mode for this read_preference.
mode | The new read preference mode. |
stdx::optional< bsoncxx::document::view > mongocxx::read_preference::tags | ( | ) | const |
Returns the current tags for this read_preference.
void mongocxx::read_preference::tags | ( | bsoncxx::document::view_or_value | tags | ) |
Sets or updates the tags for this read_preference.
tags | Document representing the tags. |