- Reference >
- MongoDB\Database Class >
- MongoDB\Database::__get()
MongoDB\Database::__get()
On this page
Definition
-
MongoDB\Database::__get
Select a collection within the database.
This method has the following parameters:
Parameter Type Description $collectionName
string The name of the collection 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: