MongoDB\ClientBulkWrite::insertOne()
New in version 2.1.
Definition
MongoDB\ClientBulkWrite::insertOne()
Specify an insert operation in the bulk write command. This method returns the
MongoDB\ClientBulkWrite
instance on which it's called.function insertOne( array|object $document, mixed &$id = null ): self
Parameters
$document
: array|object- The document to insert into the collection.
$id
: mixed- Captures the document's
_id
field value to store in an optional output variable.
Errors/Exceptions
MongoDB\Exception\InvalidArgumentException
for errors related to
the parsing of parameters or options.
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.
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
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.
See Also
Client Bulk Write section of the Bulk Write Operations guide