- Reference >
- MongoDB\Client Class >
- MongoDB\Client::selectCollection()
MongoDB\Client::selectCollection()
On this page
Definition
-
MongoDB\Client::selectCollection Selects a collection on the server.
This method has the following parameters:
Parameter Type Description $databaseNamestring The name of the database containing the collection to select. $collectionNamestring The name of the collection to select. $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 collection operations. Defaults to the client’s read concern. readPreferenceMongoDB\Driver\ReadPreference Optional. The default read preference to use for collection operations. Defaults to the client’s read preference. typeMaparray Optional. The type map to apply to cursors, which determines how BSON documents are converted to PHP values. Defaults to the client’s type map. writeConcernMongoDB\Driver\WriteConcern Optional. The default write concern to use for collection operations. Defaults to the client’s write concern.
Return Values
A MongoDB\Collection object.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
Behavior
The selected collection inherits options such as read preference and type
mapping from the Client object. Options may be
overridden via the $options parameter.
Example
The following example selects the users collection in the test database:
The following example selects the users collection in the test database
with a custom read preference: