MongoDB\ClientBulkWrite::insertOne()
バージョン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- コレクションに挿入するドキュメント。
$id
: 混合- Captures the document's
_id
field value to store in an optional output variable.
エラーと例外
MongoDB\Exception\InvalidArgumentException
は、パラメータまたはオプションの解析に関連するエラーの場合は です。
MongoDB$Driver\Exception\BulkWriteCommandException 書込み (write)操作に関連するエラーの場合getWriteErrors() によって返される値を調べて、エラーの内容を判断できます。
MongoDB\Driver\Exception\RuntimeException 拡張レベルのその他のエラー(例:)。
動作
MongoDB\Driver\Exception\BulkWriteCommandException がスローされた場合は、 getWriteErrors() を呼び出し、返された配列の情報を調べて、エラーの内容を判断できます。
例、書込み (write)操作はプライマリサーバーに正常に適用されたが、書込み保証 (write concern)を満たすには失敗した場合があります。あるいは、一意なキー制約に違反する例、書込み (write)操作が完全に失敗した可能性もあります。