(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)