array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'mongodb-driver-bulkwritecommandexception.getpartialresult.php', 1 => 'MongoDB\\Driver\\Exception\\BulkWriteCommandException::getPartialResult', 2 => 'Returns the result of any successful write operations', ), 'up' => array ( 0 => 'class.mongodb-driver-exception-bulkwritecommandexception.php', 1 => 'MongoDB\\Driver\\Exception\\BulkWriteCommandException', ), 'prev' => array ( 0 => 'mongodb-driver-bulkwritecommandexception.geterrorreply.php', 1 => 'MongoDB\\Driver\\Exception\\BulkWriteCommandException::getErrorReply', ), 'next' => array ( 0 => 'mongodb-driver-bulkwritecommandexception.getwriteconcernerrors.php', 1 => 'MongoDB\\Driver\\Exception\\BulkWriteCommandException::getWriteConcernErrors', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mongodb/mongodb/driver/exception/bulkwritecommandexception/getpartialresult.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResult

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getPartialResultReturns the result of any successful write operations

说明

final public 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

参见