MongoDBChangeStream-rewind.txt 1.56 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
===============================
MongoDB\\ChangeStream::rewind()
===============================

.. default-domain:: mongodb

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

Definition
----------

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

   Rewinds the change stream and attempts to load the first event.

   .. code-block:: php

      function rewind(): void

   This method should be called at the start of change stream iteration.

   .. note::

      Rewinding the change stream does not guarantee that there will be a
      current event to access. You should still call
      :phpmethod:`MongoDB\\ChangeStream::valid()` to check for a current event
      at each step of iteration. After initially rewinding the change stream,
      :phpmethod:`MongoDB\\ChangeStream::next()` should be used to iterate
      further.

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

:php:`MongoDB\\Driver\\Exception\\LogicException
<mongodb-driver-exception-logicexception>` if this method is called after a call
to :phpmethod:`MongoDB\\ChangeStream::next()` (i.e. the underlying
:php:`MongoDB\\Driver\\Cursor <class.mongodb-driver-cursor>` has already been
advanced).

.. include:: /includes/extracts/error-driver-runtimeexception.rst

See Also
--------

49
- :phpmethod:`MongoDB\\Client::watch()`
50
- :phpmethod:`MongoDB\\Collection::watch()`
51
- :phpmethod:`MongoDB\\Database::watch()`
52 53 54
- :php:`Iterator::rewind() <iterator.rewind>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual