Skip to content

Commit 0bb6462

Browse files
alcaeusjmikola
authored andcommitted
Add accessor for gridFS buckets in database class
1 parent 0195906 commit 0bb6462

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Database.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use MongoDB\Driver\ReadPreference;
1010
use MongoDB\Driver\WriteConcern;
1111
use MongoDB\Exception\InvalidArgumentException;
12+
use MongoDB\GridFS\Bucket;
1213
use MongoDB\Model\CollectionInfoIterator;
1314
use MongoDB\Operation\CreateCollection;
1415
use MongoDB\Operation\DatabaseCommand;
@@ -262,6 +263,26 @@ public function selectCollection($collectionName, array $options = [])
262263
return new Collection($this->manager, $this->databaseName, $collectionName, $options);
263264
}
264265

266+
/**
267+
* Select a GridFS bucket within this database.
268+
*
269+
* @see Bucket::__construct() for supported options
270+
* @param string $bucketName Name of the bucket to select (defaults to 'fs')
271+
* @param array $options Bucket constructor options
272+
* @return Bucket
273+
*/
274+
public function selectGridFSBucket($bucketName = 'fs', array $options = [])
275+
{
276+
$options += [
277+
'bucketName' => $bucketName,
278+
'readConcern' => $this->readConcern,
279+
'readPreference' => $this->readPreference,
280+
'writeConcern' => $this->writeConcern,
281+
];
282+
283+
return new Bucket($this->manager, $this->databaseName, $options);
284+
}
285+
265286
/**
266287
* Get a clone of this database with different options.
267288
*

0 commit comments

Comments
 (0)