MongoDBUpdateResult-getUpsertedId.txt 1.07 KB
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
======================================
MongoDB\\UpdateResult::getUpsertedId()
======================================

.. default-domain:: mongodb

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

Definition
----------

.. phpmethod:: MongoDB\\UpdateResult::getUpsertedId()

   Return the ID (i.e. ``_id`` field value) of the upserted document.

   .. code-block:: php

      function getUpsertedId(): mixed|null

Return Values
-------------

The ID (i.e. ``_id`` field value) of the upserted document. If no document was
upserted, ``null`` will be returned.

If the document had an ID prior to upserting (i.e. the server did not need to
generate an ID), this will contain its ``_id`` field value. Any server-generated
32
ID will be a :php:`MongoDB\\BSON\\ObjectId <class.mongodb-bson-objectid>`
33 34 35 36 37 38 39 40 41 42 43 44
instance.

Errors/Exceptions
-----------------

.. include:: /includes/extracts/error-badmethodcallexception-write-result.rst

See Also
--------

- :php:`MongoDB\\Driver\\WriteResult::getUpsertedIds()
  <manual/en/mongodb-driver-writeresult.getupsertedids.php>`