php教程

The MongoDuplicateKeyException class

(PECL mongo >= 1.5.0)

简介

Thrown when attempting to insert a document into a collection which already contains the same values for the unique keys.

类摘要

MongoDuplicateKeyException extends MongoWriteConcernException {
/* 继承的属性 */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* 继承的方法 */
}

范例

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";
}
?>

以上例程的输出类似于:

localhost:27017: insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.test.$_id_  dup key: { : 1 }

User Contributed Notes

sarahjay dot wth at gmail dot com 16-Aug-2018 05:33
Multiplication:

<!DOCTYPE html>
<html>
<body>

<?php
$x
= 10
$y = 6;

echo
$x * $y;
?> 

</body>
</html>

See More details on: http://bizmaa.com
fastest963 at gmail dot com 30-May-2014 07:08
Not sure about earlier versions but this definitely exists in pecl mongo 1.2.10.

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788