You are viewing an offline version of MongoDB documentation. Some page features might be unavailable. To view the latest version of the page or use interactive features, visit the live page.
MongoDB\Database::__get()
Definition
Parameters
$collectionName: string- The name of the database to select.
Return Values
A MongoDB\Collection object.
Behavior
The selected collection inherits options such as read preference and type
mapping from the Database object. If you wish to
override any options, use the MongoDB\Database::selectCollection()
method.
Note
To select collections whose names contain special characters, such as
., use complex syntax, as in $database->{'that.database'}.
Alternatively, MongoDB\Database::selectCollection() supports
selecting collections whose names contain special characters.
Examples
The following example selects the users and system.profile
collections from the test database:
$db = (new MongoDB\Client)->test; $users = $db->users; $systemProfile = $db->{'system.profile'};