For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

MongoDB\Collection::getReadPreference()

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)->getCollection('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"}