International PHP Conference Munich 2025

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrorsRenvoie les erreurs d'écriture

Description

final public MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors(): array

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Un tableau de MongoDB\Driver\WriteErrors qui se sont produite lors de l'exécution de l'écriture individuelle. Les clés de tableau correspondent à l'index de l'opération d'écriture dans will correspond to the index of the write operation from MongoDB\Driver\BulkWriteCommand. Cette liste contiendra au plus une entrée si l'écriture en masse était ordonnée.

Exemples

Exemple #1 Exemple de MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors()

<?php

$manager
= new MongoDB\Driver\Manager;

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

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

?>

Résultat de l'exemple ci-dessus est similaire à :

array(2) {
  [2]=>
  object(MongoDB\Driver\WriteError)#5 (4) {
    ["message"]=>
    string(78) "E11000 duplicate key error collection: db.coll index: _id_ dup key: { _id: 1 }"
    ["code"]=>
    int(11000)
    ["index"]=>
    int(2)
    ["info"]=>
    object(stdClass)#6 (0) {
    }
  }
  [3]=>
  object(MongoDB\Driver\WriteError)#7 (4) {
    ["message"]=>
    string(78) "E11000 duplicate key error collection: db.coll index: _id_ dup key: { _id: 1 }"
    ["code"]=>
    int(11000)
    ["index"]=>
    int(3)
    ["info"]=>
    object(stdClass)#8 (0) {
    }
  }
}

Voir aussi

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top