This version of the documentation is archived and no longer supported. To learn how to upgrade your version of PHP Library Manual, refer to the upgrade documentation.




Constructs a new Bucket instance.

function __construct(MongoDB\Driver\Manager $manager, $databaseName, array $options = [])

This constructor has the following parameters:

Parameter Type Description
$manager MongoDB\Driver\Manager The Manager instance from the driver. The manager maintains connections between the driver and your MongoDB instances.
$databaseName string The name of the database.
$options array Optional. An array specifying the desired options.

The $options parameter supports the following options:

Option Type Description
bucketName string Optional. The bucket name, which will be used as a prefix for the files and chunks collections. Defaults to "fs".
chunkSizeBytes integer Optional. The chunk size in bytes. Defaults to 261120 (i.e. 255 KiB).
disableMD5 boolean

Optional. Whether to disable automatic MD5 generation when storing files.

Defaults to false.

readConcern MongoDB\Driver\ReadConcern Optional. The default read concern to use for bucket operations. Defaults to the database’s read concern.
readPreference MongoDB\Driver\ReadPreference Optional. The default read preference to use for bucket operations. Defaults to the database’s read preference.
typeMap array

Optional. Default type map to apply to cursors, which determines how BSON documents are converted to PHP values. The MongoDB PHP Library uses the following type map by default:

    'array' => 'MongoDB\Model\BSONArray',
    'document' => 'MongoDB\Model\BSONDocument',
    'root' => 'MongoDB\Model\BSONDocument',
writeConcern MongoDB\Driver\WriteConcern Optional. The default write concern to use for bucket operations. Defaults to the database’s write concern.


MongoDB\Exception\InvalidArgumentException for errors related to the parsing of parameters or options.


If you construct a Bucket explicitly, the Bucket inherits any options from the MongoDB\Driver\Manager object. If you select the Bucket from a Database object, the Bucket inherits its options from that object.



$bucket = (new MongoDB\Client)->test->selectGridFSBucket();


The output would then resemble:

object(MongoDB\GridFS\Bucket)#3053 (2) {
  string(4) "test"
  string(11) "phplib_test"