MongoDB\ClientBulkWrite::createWithCollection()
New in version 2.1.
Definition
MongoDB\ClientBulkWrite::createWithCollection()
Create an instance of the
MongoDB\ClientBulkWrite
builder from the providedMongoDB\Collection
instance. You can add write operations to theClientBulkWrite
to create a new BulkWriteCommand that the library sends to the server.function createWithCollection( Collection $collection, array $options = [] ): self
Parameters
$collection
:MongoDB\Collection
- The
Collection
instance to set as the target for bulk write operations. $options
: arrayAn array specifying the desired options.
NameTypeDescriptionbypassDocumentValidation
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 feature is not supported for MongoDB server versions 6.0 and earlier. If used, the server returns an exception at execution time.
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
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).
See Also
Client Bulk Write section of the Bulk Write Operations guide