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\Client::getReadPreference()

New in version 1.2.

MongoDB\Client::getReadPreference()

Returns the read preference for this client.

function getReadPreference(): MongoDB\Driver\ReadPreference

A MongoDB\Driver\ReadPreference object.

<?php $client = new MongoDB\Client('mongodb://127.0.0.1/', [ 'readPreference' => 'primaryPreferred',]); var_dump($client->getReadPreference());

The output would then resemble:

object(MongoDB\Driver\ReadPreference)#5 (1) { ["mode"]=> string(16) "primaryPreferred"}