- Reference >
- MongoDB\Collection Class >
- MongoDB\Collection::__construct()
MongoDB\Collection::__construct()
On this page
Definition
-
MongoDB\Collection::__construct
Constructs a new
Collection
instance.This constructor has the following parameters:
Parameter Type Description $manager
MongoDB\Driver\Manager The Manager instance from the driver. The manager maintains connections between the driver and your MongoDB instances. $databaseName
string The name of the database. $collectionName
string The name of the collection. $options
array Optional. An array specifying the desired options. The
$options
parameter supports the following options:Option Type Description readConcern
MongoDB\Driver\ReadConcern Optional. The default read concern to use for collection operations. Defaults to the manager’s read concern. readPreference
MongoDB\Driver\ReadPreference Optional. The default read preference to use for collection operations. Defaults to the manager’s read preference. typeMap
array Optional. Default type map to apply to cursors, which determines how BSON documents are converted to PHP values. The MongoDB PHP Library uses the following type map by default:
writeConcern
MongoDB\Driver\WriteConcern Optional. The default write concern to use for collection operations. Defaults to the manager’s write concern.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException
for errors related to
the parsing of parameters or options.
Behavior
If you construct a Collection explicitly, the Collection inherits any options
from the MongoDB\Driver\Manager object.
If you select the Collection from a Client
or
Database
object, the Collection inherits its
options from that object.