Docs Menu
Docs Home
/ / /
PHP Library Manual
/ /

MongoDB\Database::__construct()

On this page

  • Definition
  • Parameters
  • Errors/Exceptions
  • Behavior
  • See Also
MongoDB\Database::__construct()

Constructs a new Database instance.

function __construct(
MongoDB\Driver\Manager $manager,
string $databaseName,
array $options = []
)
$manager : MongoDB\Driver\Manager
The Manager instance from the extension. The manager maintains connections between the driver and MongoDB.
$databaseName : string
The name of the database.
$options : array

An array specifying the desired options.

Name
Type
Description

readConcern

The default read concern to use for database operations. Defaults to the manager's read concern.

readPreference

The default read preference to use for database operations. Defaults to the manager's read preference.

typeMap

array

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

[
'array' => 'MongoDB\Model\BSONArray',
'document' => 'MongoDB\Model\BSONDocument',
'root' => 'MongoDB\Model\BSONDocument',
]

writeConcern

The default write concern to use for database operations. Defaults to the manager's write concern.

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

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.

Back

MongoDB\Database