- Reference >
- MongoDB\Collection Class >
- MongoDB\Collection::withOptions()
MongoDB\Collection::withOptions()
On this page
Definition
-
MongoDB\Collection::withOptions Returns a clone of the Collection object, but with different options.
This method has the following parameters:
Parameter Type Description $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 original collection’s read concern. readPreferenceMongoDB\Driver\ReadPreference Optional. The default read preference to use for collection operations. Defaults to the original collection’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 original collection’s type map. writeConcernMongoDB\Driver\WriteConcern Optional. The default write concern to use for collection operations. Defaults to the original collection’s write concern.
Return Values
A MongoDB\Collection object.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
Example
The following example clones an existing Collection object with a new read preference: