View Source Mongo.ReadPreference (mongodb-driver v1.2.0)
Determines which servers are considered suitable for read operations
A read preference consists of a mode and optional tag_sets
, max_staleness_ms, and hedge
.
The mode prioritizes between primaries and secondaries to produce either a single suitable server or a list of candidate servers.
If tag_sets and maxStalenessSeconds are set, they determine which candidate servers are eligible for selection.
If hedge is set, it configures how server hedged reads are used.
The default mode is :primary
.
The default tag_sets is a list with an empty tag set: [{}].
The default max_staleness_ms is unset.
The default hedge is unset.
mode
mode
:primary
Only an available primary is suitable.:secondary
All secondaries (and only secondaries) are candidates, but only eligible candidates (i.e. after applying tag_sets and maxStalenessSeconds) are suitable.:primary_preferred
If a primary is available, only the primary is suitable. Otherwise, all secondaries are candidates, but only eligible secondaries are suitable.:secondary_preferred
All secondaries are candidates. If there is at least one eligible secondary, only eligible secondaries are suitable. Otherwise, when there are no eligible secondaries, the primary is suitable.:nearest
The primary and all secondaries are candidates, but only eligible candidates are suitable.
Link to this section Summary
Link to this section Types
@type t() :: %{ mode: :primary | :secondary | :primary_preferred | :secondary_preferred | :nearest, tag_sets: [%{required(String.t()) => String.t()}], max_staleness_ms: non_neg_integer(), hedge: BSON.document() }
Link to this section Functions
Add read preference to the cmd
From the specs:
Use of slaveOk
There are two usages of slaveOK:
- A driver query parameter that predated read preference modes and tag set lists.
- A wire protocol flag on OP_QUERY operations