New in version 2.1.
Definition
- MongoDB\ClientBulkWrite::createWithCollection()
- Create an instance of the - MongoDB\ClientBulkWritebuilder from the provided- MongoDB\Collectioninstance. You can add write operations to the- ClientBulkWriteto create a new BulkWriteCommand that the library sends to the server.- function createWithCollection( - Collection $collection, - array $options = [] - ): self 
Parameters
- $collection:- MongoDB\Collection
- The Collectioninstance to set as the target for bulk write operations.
- $options: array
- An array specifying the desired options. NameTypeDescription- bypassDocumentValidation - boolean - If - true: the write operation ignores document level validation.- The default is - false.- comment - mixed - Enables users to specify an arbitrary comment to help trace the operation through the database profiler, currentOp output, and logs. - let - array|object - Map of parameter names and values. Values must be constant or closed expressions that do not reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. - $$var).- This is not supported for server versions prior to 5.0 and will result in an exception at execution time if used. - ordered - boolean - If - true: When a single write fails, the operation stops without performing the remaining writes and throws an exception.- If - false: When a single write fails, the operation continues with the remaining writes, if any, and throws an exception.- The default is - true.- verboseResults - boolean - Specifies whether to return verbose results. - The default is - false.
Return Values
A new ClientBulkWrite instance with an empty BulkWriteCommand
specification.
Errors/Exceptions
MongoDB\Exception\UnsupportedException if options are used and
not supported by the selected server (e.g. collation, readConcern,
writeConcern).
MongoDB\Exception\InvalidArgumentException for errors related to
the parsing of parameters or options.
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
See Also
- Client Bulk Write section of the Bulk Write Operations guide