diff --git a/src/GridFS/Bucket.php b/src/GridFS/Bucket.php
index 5a09249390ebfd7a0dbdfe7e5bedde6f53001b8f..b08f4cbdd26b169c60de888ad55a5ec40b7181de 100644
--- a/src/GridFS/Bucket.php
+++ b/src/GridFS/Bucket.php
@@ -5,6 +5,7 @@ namespace MongoDB\GridFS;
use MongoDB\BSON\ObjectId;
use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager;
+use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentException;
@@ -38,6 +39,8 @@ class Bucket
* * chunkSizeBytes (integer): The chunk size in bytes. Defaults to
* 261120 (i.e. 255 KiB).
*
+ * * readConcern (MongoDB\Driver\ReadConcern): Read concern.
+ *
* * readPreference (MongoDB\Driver\ReadPreference): Read preference.
*
* * writeConcern (MongoDB\Driver\WriteConcern): Write concern.
@@ -62,6 +65,10 @@ class Bucket
throw InvalidArgumentException::invalidType('"chunkSizeBytes" option', $options['chunkSizeBytes'], 'integer');
}
+ if (isset($options['readConcern']) && ! $options['readConcern'] instanceof ReadConcern) {
+ throw InvalidArgumentException::invalidType('"readConcern" option', $options['readConcern'], 'MongoDB\Driver\ReadConcern');
+ }
+
if (isset($options['readPreference']) && ! $options['readPreference'] instanceof ReadPreference) {
throw InvalidArgumentException::invalidType('"readPreference" option', $options['readPreference'], 'MongoDB\Driver\ReadPreference');
}
@@ -73,7 +80,7 @@ class Bucket
$this->databaseName = (string) $databaseName;
$this->options = $options;
- $collectionOptions = array_intersect_key($options, ['readPreference' => 1, 'writeConcern' => 1]);
+ $collectionOptions = array_intersect_key($options, ['readConcern' => 1, 'readPreference' => 1, 'writeConcern' => 1]);
$this->collectionWrapper = new CollectionWrapper($manager, $databaseName, $options['bucketName'], $collectionOptions);
$this->registerStreamWrapper();
diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php
index 5324c0724d37729eca08ef476b0756e74ab9d3d3..f3ca9efbe1b9f12f78f0d301c93179a9328fad56 100644
--- a/tests/GridFS/BucketFunctionalTest.php
+++ b/tests/GridFS/BucketFunctionalTest.php
@@ -3,6 +3,7 @@
namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary;
+use MongoDB\Driver\ReadConcern;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern;
use MongoDB\GridFS\Bucket;
@@ -21,6 +22,7 @@ class BucketFunctionalTest extends FunctionalTestCase
new Bucket($this->manager, $this->getDatabaseName(), [
'bucketName' => 'test',
'chunkSizeBytes' => 8192,
+ 'readConcern' => new ReadConcern(ReadConcern::LOCAL),
'readPreference' => new ReadPreference(ReadPreference::RP_PRIMARY),
'writeConcern' => new WriteConcern(WriteConcern::MAJORITY, 1000),
]);
@@ -47,6 +49,10 @@ class BucketFunctionalTest extends FunctionalTestCase
$options[][] = ['chunkSizeBytes' => $value];
}
+ foreach ($this->getInvalidReadConcernValues() as $value) {
+ $options[][] = ['readConcern' => $value];
+ }
+
foreach ($this->getInvalidReadPreferenceValues() as $value) {
$options[][] = ['readPreference' => $value];
}