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
ReadPreferencewith 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
ReadPreferencewith 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
ReadPreferencewith modesecondary. With this mode, all operations read from secondary members of the replica set.Declaration
Swift
public static let secondary: ReadPreference -
A
ReadPreferencewith 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
ReadPreferencewith 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
ReadPreferencewith 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 -> ReadPreferenceParameters
tagSetsan 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.maxStalenessSecondsan optional
Int, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreferencewith 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 -> ReadPreferenceParameters
tagSetsan 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.maxStalenessSecondsan optional
Int, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreferencewith 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 -> ReadPreferenceParameters
tagSetsan 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.maxStalenessSecondsan optional
Int, indicating a maximum replication lag, or “staleness”, for reads from secondaries. -
Initializes a new
ReadPreferencewith 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 -> ReadPreferenceParameters
tagSetsan 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.maxStalenessSecondsan optional
Int, indicating a maximum replication lag, or “staleness”, for reads from secondaries.
View on GitHub
Install in Dash
ReadPreference Structure Reference