Docs Menu
Docs Home
/ / /
PHP Library Manual
/ / /

MongoDB\InsertOneResult::getInsertedId()

On this page

  • Definition
  • Return Values
MongoDB\InsertOneResult::getInsertedId()

Return the ID (i.e. _id field value) for the inserted document.

function getInsertedId(): mixed

Since IDs are created by the driver, this method may be called irrespective of whether the write was acknowledged.

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.

← MongoDB\InsertOneResult::getInsertedCount()