The MongoDB\Driver\ReadPreference class
The read preference mode as a string (e.g. "primary", "secondary").
Intro
Class synopsis
Properties
modeThe read preference mode as a string (e.g.
"primary","secondary").tagsThe tag set list used by the read preference, or null if no tag sets were specified.
maxStalenessSecondsThe maximum staleness in seconds for reads, or
MongoDB\Driver\ReadPreference::NO_MAX_STALENESSif no maximum staleness was specified.hedgeA document specifying the hedge options for the read preference, or null if no hedge options were specified.
WarningThis property is deprecated as hedged reads are deprecated in MongoDB 8.0.
Predefined Constants
MongoDB\Driver\ReadPreference::PRIMARYAll operations read from the current replica set primary. This is the default read preference for MongoDB.
MongoDB\Driver\ReadPreference::PRIMARY_PREFERREDIn most situations, operations read from the primary but if it is unavailable, operations read from secondary members.
MongoDB\Driver\ReadPreference::SECONDARYAll operations read from the secondary members of the replica set.
MongoDB\Driver\ReadPreference::SECONDARY_PREFERREDIn most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.
MongoDB\Driver\ReadPreference::NEARESTOperations read from member of the replica set with the least network latency, irrespective of the member's type.
MongoDB\Driver\ReadPreference::NO_MAX_STALENESSThe default value for the
"maxStalenessSeconds"option is to specify no limit on maximum staleness, which means that the driver will not consider a secondary's lag when choosing where to direct a read operation.MongoDB\Driver\ReadPreference::SMALLEST_MAX_STALENESS_SECONDSThe minimum value for the
"maxStalenessSeconds"option is 90 seconds. The driver estimates secondaries' staleness by periodically checking the latest write date of each replica set member. Since these checks are infrequent, the staleness estimate is coarse. Thus, the driver cannot enforce a max staleness value of less than 90 seconds.
Changelog
| Version | Description |
|---|---|
| PECL mongodb 2.3.0 | Added public readonly properties. |
| PECL mongodb 2.0.0 | Removed the MongoDB\Driver\ReadPreference::RP_PRIMARY, MongoDB\Driver\ReadPreference::RP_PRIMARY_PREFERRED, MongoDB\Driver\ReadPreference::RP_SECONDARY, MongoDB\Driver\ReadPreference::RP_SECONDARY_PREFERRED, and MongoDB\Driver\ReadPreference::RP_NEAREST constants. The getMode method was also removed. |
| PECL mongodb 1.20.0 | Deprecated the MongoDB\Driver\ReadPreference::RP_PRIMARY, MongoDB\Driver\ReadPreference::RP_PRIMARY_PREFERRED, MongoDB\Driver\ReadPreference::RP_SECONDARY, MongoDB\Driver\ReadPreference::RP_SECONDARY_PREFERRED, and MongoDB\Driver\ReadPreference::RP_NEAREST constants. |
| PECL mongodb 1.7.0 | Added the MongoDB\Driver\ReadPreference::PRIMARY, MongoDB\Driver\ReadPreference::PRIMARY_PREFERRED, MongoDB\Driver\ReadPreference::SECONDARY, MongoDB\Driver\ReadPreference::SECONDARY_PREFERRED, and MongoDB\Driver\ReadPreference::NEAREST constants.Implements Serializable. |
| PECL mongodb 1.2.0 | Added the MongoDB\Driver\ReadPreference::NO_MAX_STALENESS and MongoDB\Driver\ReadPreference::SMALLEST_MAX_STALENESS_SECONDS constants.Implements MongoDB\BSON\Serializable. |
Readpreference