(mongodb >=1.0.0)
MongoDB\Driver\WriteError::getIndex — 返回与此 WriteError 对应的写入操作的索引
此函数没有参数。
返回与该 WriteError 对应的写入操作(来自 MongoDB\Driver\BulkWrite)的索引。
示例 #1 MongoDB\Driver\WriteError::getIndex() 示例
<?php
$manager = new MongoDB\Driver\Manager;
$bulk = new MongoDB\Driver\BulkWrite;
$bulk->insert(['_id' => 1]);
$bulk->insert(['_id' => 1]);
try {
$manager->executeBulkWrite('db.collection', $bulk);
} catch(MongoDB\Driver\Exception\BulkWriteException $e) {
var_dump($e->getWriteResult()->getWriteErrors()[0]->getIndex());
}
?>
上面的示例将输出类似于以下内容
int(1)