Docs Menu
Docs Home
/ / /
PHP Library Manual
/ /

MongoDB\ClientBulkWrite::withCollection()

New in version 2.1.

MongoDB\ClientBulkWrite::withCollection()

Return an updated instance of MongoDB\ClientBulkWrite from the provided MongoDB\Collection instance. This method allows you to add subsequent write operations on a different collection than that with which the ClientBulkWrite was created.

This method does not build a new BulkWriteCommand and does not edit the ClientBulkWrite instance in place.

function withCollection(
Collection $collection,
): self

You cannot mix Collection instances associated with different Manager objects when calling this method on a ClientBulkWrite instance. This is because the library sends the completed BulkWriteCommand to a single server.

$collection : MongoDB\Collection
The Collection instance to set as the target for write operations added to the ClientBulkWrite instance after calling withCollection().

A new ClientBulkWrite instance with the same BulkWriteCommand specification but an updated target namespace.

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).

  • Client Bulk Write section of the Bulk Write Operations guide

Back

updateOne()

On this page