- Reference >
- MongoDB\Database Class >
- MongoDB\Database::__construct()
MongoDB\Database::__construct()
On this page
Definition
-
MongoDB\Database::__construct Constructs a new
Databaseinstance.This constructor has the following parameters:
Parameter Type Description $managerMongoDB\Driver\Manager The Manager instance from the driver. The manager maintains connections between the driver and your MongoDB instances. $databaseNamestring The name of the database. $optionsarray Optional. An array specifying the desired options. The
$optionsparameter supports the following options:Option Type Description readConcernMongoDB\Driver\ReadConcern Optional. The default read concern to use for database operations. Defaults to the manager’s read concern. readPreferenceMongoDB\Driver\ReadPreference Optional. The default read preference to use for database operations. Defaults to the manager’s read preference. typeMaparray 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:
writeConcernMongoDB\Driver\WriteConcern Optional. The default write concern to use for database operations. Defaults to the manager’s write concern.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
Behavior
If you construct a Database explicitly, the Database inherits any options from
the MongoDB\Driver\Manager object. If
you select the Database from a Client object, the
Database inherits its options from that object.