You are viewing an offline version of MongoDB documentation. Some page features might be unavailable. To view the latest version of the page or use interactive features, visit the live page.
MongoDB\InsertOneResult::getInsertedId()
Definition
Return Values
The ID (i.e. _id field value) of the inserted document.
If the document had an ID prior to inserting (i.e. the driver did not need to
generate an ID), this will contain its _id field value. Any driver-generated
ID will be a MongoDB\BSON\ObjectId
instance.