« MongoDB\Driver\Exception\BulkWriteCommandException
MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResult »

MongoDB\Driver\Exception\BulkWriteCommandException::getErrorReply

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getErrorReply — Returns any top-level command error

説明

final public function MongoDB\Driver\Exception\BulkWriteCommandException::getErrorReply(): ?MongoDB\BSON\Document

パラメータ

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

戻り値

Returns any top-level error that occurred when attempting to communicate with the server or execute the bulk write. This value may be null if the exception was thrown due to errors occurring on individual writes.

例

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

<?php

$manager = new MongoDB\Driver\Manager;

// This example uses configureFailPoint to simulate a top-level command error
$manager->executeCommand('admin', new MongoDB\Driver\Command([
    'configureFailPoint' => 'failCommand',
    'mode' => ['times' => 1],
    'data' => [
        'failCommands' => ['bulkWrite'],
        'errorCode' => 8, /* UnknownError */
    ],
]));

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

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

?>

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

object(stdClass)#12 (6) {
  ["ok"]=>
  float(0)
  ["errmsg"]=>
  string(43) "Failing command via 'failCommand' failpoint"
  ["code"]=>
  int(8)
  ["codeName"]=>
  string(12) "UnknownError"
  ["$clusterTime"]=>
  object(stdClass)#10 (2) {
    ["clusterTime"]=>
    object(MongoDB\BSON\Timestamp)#6 (2) {
      ["increment"]=>
      string(1) "7"
      ["timestamp"]=>
      string(10) "1744319389"
    }
    ["signature"]=>
    object(stdClass)#9 (2) {
      ["hash"]=>
      object(MongoDB\BSON\Binary)#7 (2) {
        ["data"]=>
        string(20) ""
        ["type"]=>
        int(0)
      }
      ["keyId"]=>
      object(MongoDB\BSON\Int64)#8 (1) {
        ["integer"]=>
        string(1) "0"
      }
    }
  }
  ["operationTime"]=>
  object(MongoDB\BSON\Timestamp)#11 (2) {
    ["increment"]=>
    string(1) "7"
    ["timestamp"]=>
    string(10) "1744319389"
  }
}

参考

関連キーワード:
MongoDB   Driver   Exception   BulkWriteCommandException   command   level   getErrorReply   bulk   manager   stdClass   write   example   Manager   configureFailPoint   failCommand   bulkWrite   UnknownError   executeBulkWriteCommand   clusterTime   Timestamp   increment   timestamp   getPartialResult   mongodb   final
関連する関数・ページ:
mongodb-driver-bulkwritecommandexception.getwriteconcernerrors   class.mongodb-driver-exception-bulkwritecommandexception   mongodb-driver-bulkwritecommandexception.getpartialresult   mongodb-driver-bulkwritecommandexception.getwriteerrors   mongodb.exceptions   class.mongodb-driver-exception-commandexception