MongoDB\ClientBulkWrite::createWithCollection()

For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

MongoDB\ClientBulkWrite::createWithCollection()

New in version 2.1

Definition

Create an instance of the [MongoDB\ClientBulkWrite](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbclientbulkwrite.md#mongodb-phpclass-phpclass.MongoDB-ClientBulkWrite builder from the provided [MongoDB\Collection](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbcollection.md#mongodb-phpclass-phpclass.MongoDB-Collection instance. You can add write operations to the ClientBulkWrite to create a new BulkWriteCommand that the library sends to the server.

function createWithCollection(
    Collection $collection,
    array $options = []
): self

Parameters

$collection : [MongoDB\Collection](https://www.mongodb.com/docs/php-library/current/reference/class/mongodbcollection.md#mongodb-phpclass-phpclass.MongoDB-Collection

The Collection instance to set as the target for bulk write operations.

$options : array

An array specifying the desired options.

Name Type Description
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](https://www.mongodb.com/docs/php-library/current/reference/exception-classes.md#mongodb-phpclass-phpclass.MongoDB-Exception-UnsupportedException if options are used and not supported by the selected server (e.g. collation, readConcern, writeConcern).

[MongoDB\Exception\InvalidArgumentException](https://www.mongodb.com/docs/php-library/current/reference/exception-classes.md#mongodb-phpclass-phpclass.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](https://www.mongodb.com/docs/php-library/current/crud/bulk-write.md#std-label-php-client-bulk-write section of the Bulk Write Operations guide