The MongoDuplicateKeyException classMongoDuplicateKeyException
&reftitle.intro;
Thrown when attempting to insert a document into a collection which already contains the same values for the unique keys.
&reftitle.classsynopsis;
MongoDuplicateKeyExceptionMongoDuplicateKeyExceptionextendsMongoWriteConcernException&InheritedProperties;&InheritedMethods;
&reftitle.examples;
Catching MongoDuplicateKeyException
selectCollection("test", "test");
$c->insert(array('_id' => 1));
try {
$c->insert(array('_id' => 1));
} catch (MongoWriteConcernException $e) {
echo $e->getMessage(), "\n";
}
?>
]]>
&examples.outputs.similar;