Docs Menu
Docs Home
/ / /
PHP Library Manual
/ /

MongoDB\Collection::getReadPreference()

On this page

  • Definition
  • Return Values
  • Example
  • See Also

New in version 1.2.

MongoDB\Collection::getReadPreference()

Returns the read preference for this collection.

function getReadPreference(): MongoDB\Driver\ReadPreference

A MongoDB\Driver\ReadPreference object.

<?php
$collection = (new MongoDB\Client)->selectCollection('test', 'users', [
'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'),
]);
var_dump($collection->getReadPreference());

The output would then resemble:

object(MongoDB\Driver\ReadPreference)#5 (1) {
["mode"]=>
string(16) "primaryPreferred"
}
  • Read Preference in the MongoDB manual

  • MongoDB\Client::getReadPreference()

  • MongoDB\Database::getReadPreference()

  • MongoDB\GridFS\Bucket::getReadPreference()

Back

getReadConcern()