Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Docs Menu
Docs Home
/ / /
PHP Library Manual
/ /

MongoDB\Client::bulkWrite()

New in version 2.1.

MongoDB\Client::bulkWrite()

Perform multiple write operations across multiple namespaces.

function bulkWrite(
BulkWriteCommand|ClientBulkWrite $bulk,
array $options = []
): MongoDB\BulkWriteCommandResult
$bulk : MongoDB\ClientBulkWrite or

BulkWriteCommand

Tip

Prefer ClientBulkWrite API

We recommend using the ClientBulkWrite builder class and methods to specify write operations in a bulk write command instead of using the BulkWriteCommand class. ClientBulkWrite provides a fluent API with methods similar to CRUD methods from the MongoDB\Collection class.

Represents the assembled bulk write command or builder. MongoDB\Client::bulkWrite() supports deleteMany(), deleteOne(), insertOne(), replaceOne(), updateMany(), and updateOne() operations.

$options : array

An array specifying the desired options.

Name
Type
Description

session

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 writeConcern option when starting the transaction.

A MongoDB\BulkWriteCommandResult object.

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.

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.

Back

addSubscriber()

On this page