PHP 7.3.14 Released

The MongoDB\Driver\ReadPreference class

(mongodb >=1.0.0)


Sinopsis de la Clase

final MongoDB\Driver\ReadPreference implements MongoDB\BSON\Serializable {
/* Constants */
const integer RP_PRIMARY = 1 ;
const integer RP_PRIMARY_PREFERRED = 5 ;
const integer RP_SECONDARY = 2 ;
const integer RP_SECONDARY_PREFERRED = 6 ;
const integer RP_NEAREST = 10 ;
const integer NO_MAX_STALENESS = -1 ;
/* Métodos */
final public bsonSerialize ( void ) : object
final public __construct ( string|integer $mode [, array $tagSets = NULL [, array $options = array() ]] )
final public getMaxStalenessSeconds ( void ) : int
final public getMode ( void ) : int
final public getTagSets ( void ) : array

Constantes predefinidas


All operations read from the current replica set primary. This is the default read preference for MongoDB.


In most situations, operations read from the primary but if it is unavailable, operations read from secondary members.


All operations read from the secondary members of the replica set.


In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.


Operations read from member of the replica set with the least network latency, irrespective of the member's type.


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.


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.

Historial de cambios

Versión Descripción

Added the MongoDB\Driver\ReadPreference::NO_MAX_STALENESS and MongoDB\Driver\ReadPreference::SMALLEST_MAX_STALENESS_SECONDS constants.

Implements MongoDB\BSON\Serializable.

Tabla de contenidos

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top