final class BulkWrite implements Countable (View source)

The BulkWrite collects one or more write operations that should be sent to the server.

After adding any number of insert, update, and delete operations, the collection may be executed via Manager::executeBulkWrite(). Write operations may either be ordered (default) or unordered. Ordered write operations are sent to the server, in the order provided, for serial execution. If a write fails, any remaining operations will be aborted. Unordered operations are sent to the server in an arbitrary order where they may be executed in parallel. Any errors that occur are reported after all operations have been attempted.

Methods

__construct(array|null $options = null)

Create a new BulkWrite Constructs a new ordered (default) or unordered BulkWrite.

__wakeup()

No description

int
count()

Count expected roundtrips for executing the bulk Returns the expected number of client-to-server roundtrips required to execute all write operations in the BulkWrite.

void
delete(array|object $filter, array|null $deleteOptions = null)

Add a delete operation to the bulk

mixed
insert(array|object $document)

Add an insert operation to the bulk

update(array|object $filter, array|object $newObj, array|null $updateOptions = null)

Add an update operation to the bulk

Details

final __construct(array|null $options = null)

Create a new BulkWrite Constructs a new ordered (default) or unordered BulkWrite.

Parameters

array|null $options

Exceptions

InvalidArgumentException

final __wakeup()

No description

final int count()

Count expected roundtrips for executing the bulk Returns the expected number of client-to-server roundtrips required to execute all write operations in the BulkWrite.

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

Exceptions

InvalidArgumentException

final void delete(array|object $filter, array|null $deleteOptions = null)

Add a delete operation to the bulk

Parameters

array|object $filter

The search filter

array|null $deleteOptions

Return Value

void

Exceptions

InvalidArgumentException

final mixed insert(array|object $document)

Add an insert operation to the bulk

Parameters

array|object $document

Return Value

mixed

If the document did not have an _id, a MongoDB\BSON\ObjectId will be generated and returned; otherwise, no value is returned.

Exceptions

InvalidArgumentException

final update(array|object $filter, array|object $newObj, array|null $updateOptions = null)

Add an update operation to the bulk

Parameters

array|object $filter

The search filter

array|object $newObj

A document containing either update operators (e.g. $set) or a replacement document (i.e. only field:value expressions)

array|null $updateOptions

Exceptions

InvalidArgumentException