<?php
require_once 'CustomMongoCollection.php';

try {
    $m = new MongoClient(); // connect
    $db = $m->foo; // get the database named "foo"
    $collection = new CustomMongoCollection($db, 'test2', 'id');
    $collection->ensureIndex(array('id' => -1), array('unique' => true));

    $sampleDoc = new stdClass();
    $sampleDoc->name = 'James';
    $sampleDoc->surname = 'Bond';
    $collection->save($sampleDoc);

    $sampleDoc = new stdClass();
    $sampleDoc->name = 'James1';
    $sampleDoc->surname = 'Bond1';
    $collection->insert($sampleDoc);

} catch (MongoConnectionException $e) {
    echo $e->getMessage();
}