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

MongoDB\ClientBulkWrite::insertOne()

New in version 2.1.

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

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

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.

  • Client Bulk Write section of the Bulk Write Operations guide

Back

deleteOne()

On this page