MongoDB C++ Driver
mongocxx-3.0.2
|
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 | read_mode : std::uint8_t { read_mode::k_primary = 0x01, read_mode::k_primary_preferred = 0x05, read_mode::k_secondary = 0x02, read_mode::k_secondary_preferred = 0x06, read_mode::k_nearest = 0x0A } |
Determines which members in a replica set are acceptable to read from. More... | |
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. |
void mongocxx::read_preference::mode | ( | read_mode | mode | ) |
Sets a new mode for this read_preference.
mode | The new read preference mode. |
read_mode mongocxx::read_preference::mode | ( | ) | const |
Returns the current read_mode 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. |
stdx::optional<bsoncxx::document::view> mongocxx::read_preference::tags | ( | ) | const |
Returns the current tags for this read_preference.