Commit dec31a04 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #641

parents e651f9ae fbf6eb2c
...@@ -96,7 +96,9 @@ script was iterating the change stream, the output would then resemble: ...@@ -96,7 +96,9 @@ script was iterating the change stream, the output would then resemble:
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`Iterator::current() <iterator.current>` - :php:`Iterator::current() <iterator.current>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>` - :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
......
...@@ -53,6 +53,8 @@ The output would then resemble:: ...@@ -53,6 +53,8 @@ The output would then resemble::
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`MongoDB\\Driver\\CursorId <class.mongodb-driver-cursorid>` - :php:`MongoDB\\Driver\\CursorId <class.mongodb-driver-cursorid>`
- :php:`MongoDB\\Driver\\Cursor::getId() <manual/en/mongodb-driver-cursor.getid.php>` - :php:`MongoDB\\Driver\\Cursor::getId() <manual/en/mongodb-driver-cursor.getid.php>`
=======================================
MongoDB\\ChangeStream::getResumeToken()
=======================================
.. versionadded:: 1.5
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\ChangeStream::getResumeToken()
Returns the cached resume token that will be used to resume the change
stream.
.. code-block:: php
function getResumeToken(): array|object|null
Return Values
-------------
An array or object, or ``null`` if there is no cached resume token. The return
type will depend on the ``typeMap`` option for the ``watch()`` method used to
create the change stream.
Examples
--------
This example captures the resume token for a change stream after encountering
an ``invalidate`` event and uses it to construct a second change stream using
the ``startAfter`` option.
.. code-block:: php
<?php
$uri = 'mongodb://rs1.example.com,rs2.example.com/?replicaSet=myReplicaSet';
$collection = (new MongoDB\Client($uri))->test->inventory;
$changeStream = $collection->watch();
for ($changeStream->rewind(); true; $changeStream->next()) {
if ( ! $changeStream->valid()) {
continue;
}
$event = $changeStream->current();
if ($event['operationType'] === 'invalidate') {
$startAfter = $changeStream->getResumeToken();
break;
}
printf("%d: %s\n", $changeStream->key(), $event['operationType']);
}
$changeStream = $collection->watch([], ['startAfter' => $startAfter]);
See Also
--------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :manual:`Resume a Change Stream </changeStreams#resume-a-change-stream>`
documentation in the MongoDB manual
...@@ -68,7 +68,9 @@ script was iterating the change stream, the output would then resemble: ...@@ -68,7 +68,9 @@ script was iterating the change stream, the output would then resemble:
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`Iterator::key() <iterator.key>` - :php:`Iterator::key() <iterator.key>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>` - :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
\ No newline at end of file
...@@ -36,7 +36,9 @@ Errors/Exceptions ...@@ -36,7 +36,9 @@ Errors/Exceptions
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`Iterator::next() <iterator.next>` - :php:`Iterator::next() <iterator.next>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>` - :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
...@@ -46,7 +46,9 @@ advanced). ...@@ -46,7 +46,9 @@ advanced).
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`Iterator::rewind() <iterator.rewind>` - :php:`Iterator::rewind() <iterator.rewind>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>` - :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
...@@ -34,7 +34,9 @@ A boolean indicating whether there is a current event in the change stream. ...@@ -34,7 +34,9 @@ A boolean indicating whether there is a current event in the change stream.
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Collection::watch()` - :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :php:`Iterator::valid() <iterator.valid>` - :php:`Iterator::valid() <iterator.valid>`
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>` - :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
...@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble: ...@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble:
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in - :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
the MongoDB Manual the MongoDB Manual
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
......
...@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble: ...@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble:
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Client::watch()`
- :phpmethod:`MongoDB\\Database::watch()`
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in - :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
the MongoDB Manual the MongoDB Manual
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
......
...@@ -113,6 +113,8 @@ script was iterating the change stream, the output would then resemble: ...@@ -113,6 +113,8 @@ script was iterating the change stream, the output would then resemble:
See Also See Also
-------- --------
- :phpmethod:`MongoDB\\Collection::watch()`
- :phpmethod:`MongoDB\\Client::watch()`
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in - :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
the MongoDB Manual the MongoDB Manual
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual - :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual
......
...@@ -22,6 +22,8 @@ Definition ...@@ -22,6 +22,8 @@ Definition
This class extends PHP's :php:`Iterator <manual/en/class.iterator.php>` This class extends PHP's :php:`Iterator <manual/en/class.iterator.php>`
interface. An instance of this class is returned by interface. An instance of this class is returned by
:phpmethod:`MongoDB\\Client::watch()`,
:phpmethod:`MongoDB\\Database::watch()`, and
:phpmethod:`MongoDB\\Collection::watch()`. :phpmethod:`MongoDB\\Collection::watch()`.
This class allows for iteration of events in a change stream. It also allows This class allows for iteration of events in a change stream. It also allows
...@@ -36,6 +38,7 @@ Methods ...@@ -36,6 +38,7 @@ Methods
/reference/method/MongoDBChangeStream-current /reference/method/MongoDBChangeStream-current
/reference/method/MongoDBChangeStream-getCursorId /reference/method/MongoDBChangeStream-getCursorId
/reference/method/MongoDBChangeStream-getResumeToken
/reference/method/MongoDBChangeStream-key /reference/method/MongoDBChangeStream-key
/reference/method/MongoDBChangeStream-next /reference/method/MongoDBChangeStream-next
/reference/method/MongoDBChangeStream-rewind /reference/method/MongoDBChangeStream-rewind
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment