The MongoDuplicateKeyException class MongoDuplicateKeyException
&reftitle.intro; Thrown when attempting to insert a document into a collection which already contains the same values for the unique keys.
&reftitle.classsynopsis; MongoDuplicateKeyException MongoDuplicateKeyException extends MongoWriteConcernException &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;