(mongodb >=1.0.0)

MongoDB\Driver\Manager::getReadPreferenceReturn the ReadPreference for the Manager


final public MongoDB\Driver\Manager::getReadPreference(): MongoDB\Driver\ReadPreference

Returns the MongoDB\Driver\ReadPreference for the Manager, which is derived from its URI options. This is the default read preference for queries and commands executed on the Manager.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

The MongoDB\Driver\ReadPreference for the Manager.

Erreurs / Exceptions

  • Lance une exception MongoDB\Driver\InvalidArgumentException lors d'une erreur survenue pendant l'analyse d'un argument.


Exemple #1 MongoDB\Driver\Manager::getReadPreference() example


= new MongoDB\Driver\Manager('mongodb://localhost:27017');

$manager = new MongoDB\Driver\Manager('mongodb://localhost:27017/?readPreference=secondaryPreferred&readPreferenceTags=dc:ny,rack:1&readPreferenceTags=dc:ny&readPreferenceTags=');


Résultat de l'exemple ci-dessus est similaire à :

object(MongoDB\Driver\ReadPreference)#2 (1) {
  string(7) "primary"
object(MongoDB\Driver\ReadPreference)#1 (2) {
  string(18) "secondaryPreferred"
  array(3) {
    object(stdClass)#3 (2) {
      string(2) "ny"
      string(1) "1"
    object(stdClass)#4 (1) {
      string(2) "ny"
    object(stdClass)#5 (0) {
add a note

User Contributed Notes

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