MongoDBChangeStream-getCursorId.txt 1.19 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
====================================
MongoDB\\ChangeStream::getCursorId()
====================================

.. default-domain:: mongodb

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

Definition
----------

.. phpmethod:: MongoDB\\ChangeStream::getCursorId()

   Returns the change stream cursor's ID.

   .. code-block:: php

      function getCursorId(): MongoDB\Driver\CursorId

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

A :php:`MongoDB\\Driver\\CursorId <class.mongodb-driver-cursorid>` object.

Examples
--------

This example reports the cursor ID for a change stream.

.. code-block:: php

   <?php

   $uri = 'mongodb://rs1.example.com,rs2.example.com/?replicaSet=myReplicaSet';

   $collection = (new MongoDB\Client($uri))->test->inventory;

   $changeStream = $collection->watch();

   var_dump($changeStream->getCursorId());

The output would then resemble::

   object(MongoDB\Driver\CursorId)#5 (1) {
     ["id"]=>
     int(8462642181784669708)
   }

See Also
--------

- :phpmethod:`MongoDB\\Collection::watch()`
- :php:`MongoDB\\Driver\\CursorId <class.mongodb-driver-cursorid>`
- :php:`MongoDB\\Driver\\Cursor::getId() <manual/en/mongodb-driver-cursor.getid.php>`