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::getCollection() method.
Note
To select collections whose names contain special characters, such as ., use complex syntax, as in $database->{'that.database'}.
Alternatively, MongoDB\Database::getCollection() 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'};
See Also
Property Overloading in the PHP Manual