PHP - Manual: MongoDB\Driver\ReadPreference
2025-10-23
(mongodb >=1.0.0)
MongoDB\Driver\ReadPreference::RP_PRIMARYAll operations read from the current replica set primary. This is the default read preference for MongoDB.
This constant has been DEPRECATED as of extension
version 1.20.0 and will be removed in 2.0. Applications should use
MongoDB\Driver\ReadPreference::PRIMARY instead.
MongoDB\Driver\ReadPreference::RP_PRIMARY_PREFERREDIn most situations, operations read from the primary but if it is unavailable, operations read from secondary members.
This constant has been DEPRECATED as of extension
version 1.20.0 and will be removed in 2.0. Applications should use
MongoDB\Driver\ReadPreference::PRIMARY_PREFERRED instead.
MongoDB\Driver\ReadPreference::RP_SECONDARYAll operations read from the secondary members of the replica set.
This constant has been DEPRECATED as of extension
version 1.20.0 and will be removed in 2.0. Applications should use
MongoDB\Driver\ReadPreference::SECONDARY instead.
MongoDB\Driver\ReadPreference::RP_SECONDARY_PREFERREDIn most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.
This constant has been DEPRECATED as of extension
version 1.20.0 and will be removed in 2.0. Applications should use
MongoDB\Driver\ReadPreference::SECONDARY_PREFERRED instead.
MongoDB\Driver\ReadPreference::RP_NEARESTOperations read from member of the replica set with the least network latency, irrespective of the member's type.
This constant has been DEPRECATED as of extension
version 1.20.0 and will be removed in 2.0. Applications should use
MongoDB\Driver\ReadPreference::NEAREST instead.
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_STALENESS
The 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_SECONDS
The 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.
| 版本 | 说明 |
|---|---|
| PECL mongodb 1.20.0 |
Deprecated the
|
| PECL mongodb 1.7.0 |
Added the
Implements Serializable. |
| PECL mongodb 1.2.0 |
Added the
Implements MongoDB\BSON\Serializable. |
官方地址:https://www.php.net/manual/en/class.mongodb-driver-readpreference.php