New in version 2.1.
Definition
Parameters
$bulk:MongoDB\ClientBulkWriteorTip
Prefer ClientBulkWrite API
We recommend using the
ClientBulkWritebuilder class and methods to specify write operations in a bulk write command instead of using theBulkWriteCommandclass.ClientBulkWriteprovides a fluent API with methods similar to CRUD methods from theMongoDB\Collectionclass.Represents the assembled bulk write command or builder.
MongoDB\Client::bulkWrite()supportsdeleteMany(),deleteOne(),insertOne(),replaceOne(),updateMany(), andupdateOne()operations.$options: arrayAn array specifying the desired options.
NameTypeDescriptionsession
Client session to associate with the operation.
writeConcern
Write concern to use for the operation. Defaults to the collection's write concern.
It is not possible to specify a write concern for individual operations as part of a transaction. Instead, set the
writeConcernoption when starting the transaction.
Return Values
A MongoDB\BulkWriteCommandResult object.
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).
MongoDB\Driver\Exception\BulkWriteCommandException for errors related to the write operation. You can inspect the value returned by getWriteErrors() to determine the nature of the error.
Behavior
If a MongoDB\Driver\Exception\BulkWriteCommandException is thrown, you can call getWriteErrors() and inspect the information in the returned array to determine the nature of the error.
For example, a write operation may have been successfully applied to the primary server but failed to satisfy the write concern. Alternatively, a write operation may have failed outright, for example for violating the unique key constraint.
In the case of a bulk write, the result might indicate multiple successful write
operations and/or errors. If the ordered option is true, some
operations may have succeeded before the first error was encountered and the
exception thrown. If the ordered option is false, multiple errors may
have been encountered.