PHP 8.5.0 Alpha 1 available for testing

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrors

(mongodb >=2.1.0)

MongoDB\Driver\Exception\BulkWriteCommandException::getWriteErrorsDevuelve los errores de escritura

Descripción

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

Parámetros

Esta función no tiene parámetros.

Valores devueltos

Un array de MongoDB\Driver\WriteError que se produjeron durante la ejecución de la escritura individual. Las claves del array corresponden al índice de la operación de escritura en MongoDB\Driver\BulkWriteCommand. Esta lista contendrá como máximo una entrada si la escritura masiva estaba ordenada.

Ejemplos

Ejemplo #1 Ejemplo 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());
}

?>

El resultado del ejemplo sería algo similar a:

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) {
    }
  }
}

Ver también

add a note

User Contributed Notes

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