As all the exceptions are extending the base Exception class, you can get the code with the getCode() method:
<?php
try {
$collection->insert($duplicate_document, array('safe' => true));
} catch (MongoCursorException $e) {
printf("Error code is %d.\n", $e->getCode();
exit(1);
}