The MongoDuplicateKeyException class
(PECL mongo >= 1.5.0)
Introduction
Thrown when attempting to insert a document into a collection which already contains the same values for the unique keys.
Class synopsis
MongoDuplicateKeyException
extends
MongoWriteConcernException
{
/* Inherited properties */
/* Inherited methods */
}Examples
Example #1 Catching MongoDuplicateKeyException
<?php
$mc = new MongoClient("localhost");
$c = $mc->selectCollection("test", "test");
$c->insert(array('_id' => 1));
try {
$c->insert(array('_id' => 1));
} catch (MongoWriteConcernException $e) {
echo $e->getMessage(), "\n";
}
?>
The above examples will output something similar to:
localhost:27017: insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.test.$_id_ dup key: { : 1 }
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- The MongoException class
- The MongoResultException class
- The MongoCursorException class
- The MongoCursorTimeoutException class
- The MongoConnectionException class
- The MongoGridFSException class
- The MongoDuplicateKeyException class
- The MongoProtocolException class
- The MongoExecutionTimeoutException class
- The MongoWriteConcernException class
Коментарии
Not sure about earlier versions but this definitely exists in pecl mongo 1.2.10.
Multiplication:
<!DOCTYPE html>
<html>
<body>
<?php
$x = 10;
$y = 6;
echo $x * $y;
?>
</body>
</html>
See More details on: http://bizmaa.com