Mark Mark -5 years ago 283
PHP Question

Mongodb php get id of new document?

Creating a document:

// $newDocID = ???

I'm trying to get the new document's id. How? Thanks.

Answer Source

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

$newDocID = $content['_id'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download