Skip to content

Sending default read concern to the server #326

@petr-buchin

Description

@petr-buchin

From what I read in MongoDB Driver Specifications, driver must omit default read concern, if specified. As far as I understand, the default read concern in PHP can be obtained as follows:

$readConcern = new \MongoDB\Driver\ReadConcern();
null === $readConcern->getLevel(); // true

// or:

$readConcern = (new \MongoDB\Driver\Manager())->getReadConcern();
null === $readConcern->getLevel(); // true

But from what I see in a code of this library , the default read concern can be sent to the server by the library.
For example:

// \MongoDB\Driver\Manager instance is created internally in Client's constructor
$client = new \MongoDB\Client();

// By default, Database instance will inherit read concern from \MongoDB\Driver\Manager instance,
// constructed in Client's constructor. Collection instance will inherit readConcern, writeConcern
// and readPreference from Database. This means that $collection->readConcern for now contains
// default read concern.
$collection = $client->selectDatabase('test')->selectCollection('test');

// Find operation will inherit "readConcern" option from Collection. Thus, default read concern
// will not be omitted and will be sent to the server.
$cursor = $collection->find([]);

So I have a question whether this is an expected behavior or should this behavior be fixed.
Does the low-level driver remove default read concern and write concern before sending a query to the MongoDB server?
It worth noting, that the same logic applies to the write concern and writing commands, i.e. default write concern can be sent to the server with writing commands.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions