Alex Rivera | Logout

Mongodb php get id of new document?

Asked 2010-12-24T09:57:36.040
36

Creating a document:

$db->collection->insert($content);
// $newDocID = ???

How to get the new document's id?

Edit
Report

1 Answer

62

According to the docs the array you pass to insert will be amended with an _id field:

$db->collection->insert($content);
$newDocID = $content['_id'];
answered 2010-12-24T10:38:00.853

Your Answer