MongoDBInsertOneResult-getInsertedId.txt 920 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
=========================================
MongoDB\\InsertOneResult::getInsertedId()
=========================================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: singlecol

Definition
----------

.. phpmethod:: MongoDB\\InsertOneResult::getInsertedId()

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

   .. code-block:: php

      function getInsertedId(): mixed

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

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
34
ID will be a :php:`MongoDB\\BSON\\ObjectId <class.mongodb-bson-objectid>`
35
instance.