Utilities for choosing which member of a replica set to read from.
Primary read preference.
Read preference as a document.
The mode of this read preference instance.
The name of this read preference.
PrimaryPreferred read preference.
Parameters: |
|
---|
Read preference as a document.
The maximum estimated length of time (in seconds) a replica set secondary can fall behind the primary in replication before it will no longer be selected for operations, or -1 for no maximum.
The wire protocol version the server must support.
Some read preferences impose version requirements on all servers (e.g. maxStalenessSeconds requires MongoDB 3.4 / maxWireVersion 5).
All servers’ maxWireVersion must be at least this read preference’s min_wire_version, or the driver raises ConfigurationError.
The mode of this read preference instance.
The mongos mode of this read preference.
The name of this read preference.
Set tag_sets to a list of dictionaries like [{‘dc’: ‘ny’}] to read only from members whose dc tag has the value "ny". To specify a priority-order for tag sets, provide a list of tag sets: [{'dc': 'ny'}, {'dc': 'la'}, {}]. A final, empty tag set, {}, means “read from any member that matches the mode, ignoring tags.” MongoReplicaSetClient tries each set of tags in turn until it finds a set of tags with at least one matching member.
See also
Secondary read preference.
Parameters: |
|
---|
Read preference as a document.
The maximum estimated length of time (in seconds) a replica set secondary can fall behind the primary in replication before it will no longer be selected for operations, or -1 for no maximum.
The wire protocol version the server must support.
Some read preferences impose version requirements on all servers (e.g. maxStalenessSeconds requires MongoDB 3.4 / maxWireVersion 5).
All servers’ maxWireVersion must be at least this read preference’s min_wire_version, or the driver raises ConfigurationError.
The mode of this read preference instance.
The mongos mode of this read preference.
The name of this read preference.
Set tag_sets to a list of dictionaries like [{‘dc’: ‘ny’}] to read only from members whose dc tag has the value "ny". To specify a priority-order for tag sets, provide a list of tag sets: [{'dc': 'ny'}, {'dc': 'la'}, {}]. A final, empty tag set, {}, means “read from any member that matches the mode, ignoring tags.” MongoReplicaSetClient tries each set of tags in turn until it finds a set of tags with at least one matching member.
See also
SecondaryPreferred read preference.
Parameters: |
|
---|
Read preference as a document.
The maximum estimated length of time (in seconds) a replica set secondary can fall behind the primary in replication before it will no longer be selected for operations, or -1 for no maximum.
The wire protocol version the server must support.
Some read preferences impose version requirements on all servers (e.g. maxStalenessSeconds requires MongoDB 3.4 / maxWireVersion 5).
All servers’ maxWireVersion must be at least this read preference’s min_wire_version, or the driver raises ConfigurationError.
The mode of this read preference instance.
The mongos mode of this read preference.
The name of this read preference.
Set tag_sets to a list of dictionaries like [{‘dc’: ‘ny’}] to read only from members whose dc tag has the value "ny". To specify a priority-order for tag sets, provide a list of tag sets: [{'dc': 'ny'}, {'dc': 'la'}, {}]. A final, empty tag set, {}, means “read from any member that matches the mode, ignoring tags.” MongoReplicaSetClient tries each set of tags in turn until it finds a set of tags with at least one matching member.
See also
Nearest read preference.
Parameters: |
|
---|
Read preference as a document.
The maximum estimated length of time (in seconds) a replica set secondary can fall behind the primary in replication before it will no longer be selected for operations, or -1 for no maximum.
The wire protocol version the server must support.
Some read preferences impose version requirements on all servers (e.g. maxStalenessSeconds requires MongoDB 3.4 / maxWireVersion 5).
All servers’ maxWireVersion must be at least this read preference’s min_wire_version, or the driver raises ConfigurationError.
The mode of this read preference instance.
The mongos mode of this read preference.
The name of this read preference.
Set tag_sets to a list of dictionaries like [{‘dc’: ‘ny’}] to read only from members whose dc tag has the value "ny". To specify a priority-order for tag sets, provide a list of tag sets: [{'dc': 'ny'}, {'dc': 'la'}, {}]. A final, empty tag set, {}, means “read from any member that matches the mode, ignoring tags.” MongoReplicaSetClient tries each set of tags in turn until it finds a set of tags with at least one matching member.
See also
An enum that defines the read preference modes supported by PyMongo.
See High Availability and PyMongo for code examples.
A read preference is used in three cases:
MongoClient connected to a single mongod:
MongoClient initialized with the replicaSet option:
MongoClient connected to a mongos, with a sharded cluster of replica sets: