« MongoDB\Driver\Exception\BulkWriteCommandException::getWriteConcernErrors
MongoDB\Driver\Exception\CommandException »

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors — Returns any write errors

説明

final public function MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors(): array

パラメータ

この関数にはパラメータはありません。

戻り値

An array of any MongoDB\Driver\WriteErrors that occurred during the execution of individual write operations. Array keys will correspond to the index of the write operation from MongoDB\Driver\BulkWriteCommand. This map will contain at most one entry if the bulk write was ordered.

例

例1 MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors() example

<?php

$manager = new MongoDB\Driver\Manager;

$bulk = new MongoDB\Driver\BulkWriteCommand(['ordered' => false]);
$bulk->deleteMany('db.coll', []);
$bulk->insertOne('db.coll', ['_id' => 1]);
$bulk->insertOne('db.coll', ['_id' => 1]);
$bulk->insertOne('db.coll', ['_id' => 1]);

try {
    $result = $manager->executeBulkWriteCommand($bulk);
} catch (MongoDB\Driver\Exception\BulkWriteCommandException $e) {
    var_dump($e->getWriteErrors());
}

?>

上の例の出力は、 たとえば以下のようになります。

array(2) {
  [2]=>
  object(MongoDB\Driver\WriteError)#5 (4) {
    ["message"]=>
    string(78) "E11000 duplicate key error collection: db.coll index: _id_ dup key: { _id: 1 }"
    ["code"]=>
    int(11000)
    ["index"]=>
    int(2)
    ["info"]=>
    object(stdClass)#6 (0) {
    }
  }
  [3]=>
  object(MongoDB\Driver\WriteError)#7 (4) {
    ["message"]=>
    string(78) "E11000 duplicate key error collection: db.coll index: _id_ dup key: { _id: 1 }"
    ["code"]=>
    int(11000)
    ["index"]=>
    int(3)
    ["info"]=>
    object(stdClass)#8 (0) {
    }
  }
}

参考

関連キーワード:
MongoDB   Driver   Exception   write   BulkWriteCommandException   bulk   coll   getWriteErrors   index   WriteError   errors   insertOne   operations   BulkWriteCommand   ordered   manager   Manager   executeBulkWriteCommand   message   duplicate   collection   code   info   stdClass   getWriteConcernErrors
関連する関数・ページ:
mongodb-driver-bulkwritecommandexception.getpartialresult   mongodb-driver-bulkwritecommandexception.getwriteconcernerrors   mongodb-driver-writeresult.getwriteerrors   class.mongodb-driver-exception-bulkwritecommandexception   mongodb-driver-bulkwritecommandexception.geterrorreply   mongodb-driver-manager.executebulkwritecommand