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

MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResult

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResult — Returns the result of any successful write operations

説明

final public function MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResult(): ?MongoDB\Driver\BulkWriteCommandResult

パラメータ

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

戻り値

Returns a MongoDB\Driver\BulkWriteCommandResult reporting the result of any successful operations that were performed before the error was encountered. The return value will be null if it cannot be determined that at least one write was successfully performed (and acknowledged).

例

例1 Partial result if at least one write is successful

<?php

$manager = new MongoDB\Driver\Manager;

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

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

var_dump($result?->getInsertedCount());

?>

上の例の出力は以下となります。

int(1)

例2 No partial result if no writes are successful

<?php

$manager = new MongoDB\Driver\Manager;

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

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

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

var_dump($result?->getInsertedCount());

?>

上の例の出力は以下となります。

NULL

参考

関連キーワード:
MongoDB   Driver   bulk   Exception   BulkWriteCommandException   successful   write   coll   operations   getPartialResult   manager   insertOne   executeBulkWriteCommand   BulkWriteCommandResult   Manager   BulkWriteCommand   performed   least   deleteMany   catch   dump   getInsertedCount   getErrorReply   getWriteConcernErrors   mongodb
関連する関数・ページ:
mongodb-driver-bulkwritecommandexception.getwriteerrors   mongodb-driver-bulkwritecommandexception.getwriteconcernerrors   mongodb-driver-manager.executebulkwritecommand   class.mongodb-driver-exception-bulkwritecommandexception   mongodb-driver-bulkwritecommandexception.geterrorreply   class.mongodb-driver-bulkwritecommand