Creating a document:
$db->collection->insert($content);
// $newDocID = ???
I'm trying to get the new document's id. How? Thanks.
Creating a document:
$db->collection->insert($content);
// $newDocID = ???
I'm trying to get the new document's id. How? Thanks.
 
    
    According to the docs the array you pass to insert will be amended with an _id field:
$db->collection->insert($content);
$newDocID = $content['_id'];
 
    
    You can also get _id before insert. Just add _id field to document with new MongoId ie.
$content['_id'] = new MongoId();
$db->collection->insert($content);
Also there are nice benefits of this:
This works for me:
$insertResult = $collection->insertOne($object);
$id = $insertResult->getInsertedId();
 
    
     $newDocument = $db->collection->findAndModify ( $row, $row, null, array('new'=>true,'upsert' => true));
 $strId = $newDocument['_id']->{'$id'};
