ReadPreference
public struct ReadPreference : Equatable
Represents a MongoDB read preference, indicating which member(s) of a replica set read operations should be directed to.
-
An enumeration of possible read preference modes.
See moreDeclaration
Swift
public enum Mode : String
-
The mode specified for this read preference.
Declaration
Swift
public var mode: Mode
-
Optionally specified ordered array of tag sets. If provided, a server will only be considered suitable if its tags are a superset of at least one of the tag sets.
Declaration
Swift
public var tagSets: [BSONDocument]?
-
An optionally specified value indicating a maximum replication lag, or “staleness”, for reads from secondaries.
Declaration
Swift
public var maxStalenessSeconds: Int?
-
A
ReadPreference
with modeprimary
. This is the default mode. With this mode, all operations read from the current replica set primary.Declaration
Swift
public static let primary: ReadPreference
-
A
ReadPreference
with modeprimaryPreferred
. With this mode, in most situations operations read from the primary, but if it is unavailable, operations read from secondary members.Declaration
Swift
public static let primaryPreferred: ReadPreference
-
A
ReadPreference
with modesecondary
. With this mode, all operations read from secondary members of the replica set.Declaration
Swift
public static let secondary: ReadPreference
-
A
ReadPreference
with modesecondaryPreferred
. With this mode, in most situations operations read from secondary members, but if no secondary members are available, operations read from the primary.Declaration
Swift
public static let secondaryPreferred: ReadPreference
-
A
ReadPreference
with modenearest
. With this mode, operations read from the member of the replica set with the least network latency, irrespective of the member’s type.Declaration
Swift
public static let nearest: ReadPreference
-
Initializes a new
ReadPreference
with the modeprimaryPreferred
. With this mode, in most situations operations read from the primary, but if it is unavailable, operations read from secondary members.Declaration
Swift
public static func primaryPreferred( tagSets: [BSONDocument]? = nil, maxStalenessSeconds: Int? = nil ) throws -> ReadPreference
Parameters
tagSets
an optional
[Document]
, containing an ordered array of tag sets. If provided, a server will only be considered suitable if its tags are a superset of at least one of the tag sets.maxStalenessSeconds
an optional
Int
, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreference
with the modesecondary
. With this mode, all operations read from the secondary members of the replica set.Declaration
Swift
public static func secondary( tagSets: [BSONDocument]? = nil, maxStalenessSeconds: Int? = nil ) throws -> ReadPreference
Parameters
tagSets
an optional
[Document]
, containing an ordered array of tag sets. If provided, a server will only be considered suitable if its tags are a superset of at least one of the tag sets.maxStalenessSeconds
an optional
Int
, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreference
with the modesecondaryPreferred
. With this mode, in most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.Declaration
Swift
public static func secondaryPreferred( tagSets: [BSONDocument]? = nil, maxStalenessSeconds: Int? = nil ) throws -> ReadPreference
Parameters
tagSets
an optional
[Document]
, containing an ordered array of tag sets. If provided, a server will only be considered suitable if its tags are a superset of at least one of the tag sets.maxStalenessSeconds
an optional
Int
, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreference
with the modenearest
. With this mode, operations read from the member of the replica set with the least network latency, irrespective of the member’s type.Declaration
Swift
public static func nearest( tagSets: [BSONDocument]? = nil, maxStalenessSeconds: Int? = nil ) throws -> ReadPreference
Parameters
tagSets
an optional
[Document]
, containing an ordered array of tag sets. If provided, a server will only be considered suitable if its tags are a superset of at least one of the tag sets.maxStalenessSeconds
an optional
Int
, indicating a maximum replication lag, or “staleness”, for reads from secondaries.