MongoDB\Database::selectGridFSBucket()
Definition
Parameters
$options
: arrayAn array specifying the desired options.
NameTypeDescriptionbucketNamestringThe bucket name, which will be used as a prefix for the files and chunks collections. Defaults to"fs"
.chunkSizeBytesintegerThe chunk size in bytes. Defaults to261120
(i.e. 255 KiB).codecMongoDB\Codec\DocumentCodecThe default codec to use for bucket methods that return a file document (e.g.
MongoDB\GridFS\Bucket::find()
).New in version 1.17.
disableMD5booleanWhether to disable automatic MD5 generation when storing files.
Defaults to
false
. Onlytrue
will be supported in 2.0.New in version 1.4.
readConcernThe default read concern to use for bucket operations. Defaults to the database's read concern.readPreferenceThe default read preference to use for bucket operations. Defaults to the database's read concern.typeMaparrayThe default type map to use for bucket operations. Defaults to the database's type map.writeConcernThe default write concern to use for bucket operations. Defaults to the database's write concern.
Return Values
A MongoDB\GridFS\Bucket
object.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException
for errors related to
the parsing of parameters or options.
Behavior
The selected bucket inherits options such as read preference and type
mapping from the Database
object. Options may be
overridden via the $options
parameter.
Example
The following example selects the default fs.files
bucket in the test
database:
$db = (new MongoDB\Client)->test; $bucket = $db->selectGridFSBucket();
The following example selects the custom images.files
bucket in the test
database with a custom read preference:
$db = (new MongoDB\Client)->test; $imagesBucket = $db->selectGridFSBucket([ 'bucketName' => 'images', 'readPreference' => new MongoDB\Driver\ReadPreference('primaryPreferred'), ]);