Skip to content

Commit cb6efc5

Browse files
committed
Merge pull request #641
2 parents 823d1e8 + 359fe86 commit cb6efc5

11 files changed

+96
-0
lines changed

source/reference/method/MongoDBChangeStream-current.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ script was iterating the change stream, the output would then resemble:
9696
See Also
9797
--------
9898

99+
- :phpmethod:`MongoDB\\Client::watch()`
99100
- :phpmethod:`MongoDB\\Collection::watch()`
101+
- :phpmethod:`MongoDB\\Database::watch()`
100102
- :php:`Iterator::current() <iterator.current>`
101103
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
102104
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBChangeStream-getCursorId.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ The output would then resemble::
5353
See Also
5454
--------
5555

56+
- :phpmethod:`MongoDB\\Client::watch()`
5657
- :phpmethod:`MongoDB\\Collection::watch()`
58+
- :phpmethod:`MongoDB\\Database::watch()`
5759
- :php:`MongoDB\\Driver\\CursorId <class.mongodb-driver-cursorid>`
5860
- :php:`MongoDB\\Driver\\Cursor::getId() <manual/en/mongodb-driver-cursor.getid.php>`
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
=======================================
2+
MongoDB\\ChangeStream::getResumeToken()
3+
=======================================
4+
5+
.. versionadded:: 1.5
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Definition
16+
----------
17+
18+
.. phpmethod:: MongoDB\\ChangeStream::getResumeToken()
19+
20+
Returns the cached resume token that will be used to resume the change
21+
stream.
22+
23+
.. code-block:: php
24+
25+
function getResumeToken(): array|object|null
26+
27+
Return Values
28+
-------------
29+
30+
An array or object, or ``null`` if there is no cached resume token. The return
31+
type will depend on the ``typeMap`` option for the ``watch()`` method used to
32+
create the change stream.
33+
34+
Examples
35+
--------
36+
37+
This example captures the resume token for a change stream after encountering
38+
an ``invalidate`` event and uses it to construct a second change stream using
39+
the ``startAfter`` option.
40+
41+
.. code-block:: php
42+
43+
<?php
44+
45+
$uri = 'mongodb://rs1.example.com,rs2.example.com/?replicaSet=myReplicaSet';
46+
47+
$collection = (new MongoDB\Client($uri))->test->inventory;
48+
49+
$changeStream = $collection->watch();
50+
51+
for ($changeStream->rewind(); true; $changeStream->next()) {
52+
if ( ! $changeStream->valid()) {
53+
continue;
54+
}
55+
56+
$event = $changeStream->current();
57+
58+
if ($event['operationType'] === 'invalidate') {
59+
$startAfter = $changeStream->getResumeToken();
60+
break;
61+
}
62+
63+
printf("%d: %s\n", $changeStream->key(), $event['operationType']);
64+
}
65+
66+
$changeStream = $collection->watch([], ['startAfter' => $startAfter]);
67+
68+
See Also
69+
--------
70+
71+
- :phpmethod:`MongoDB\\Client::watch()`
72+
- :phpmethod:`MongoDB\\Collection::watch()`
73+
- :phpmethod:`MongoDB\\Database::watch()`
74+
- :manual:`Resume a Change Stream </changeStreams#resume-a-change-stream>`
75+
documentation in the MongoDB manual

source/reference/method/MongoDBChangeStream-key.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ script was iterating the change stream, the output would then resemble:
6868
See Also
6969
--------
7070

71+
- :phpmethod:`MongoDB\\Client::watch()`
7172
- :phpmethod:`MongoDB\\Collection::watch()`
73+
- :phpmethod:`MongoDB\\Database::watch()`
7274
- :php:`Iterator::key() <iterator.key>`
7375
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
7476
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBChangeStream-next.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ Errors/Exceptions
3636
See Also
3737
--------
3838

39+
- :phpmethod:`MongoDB\\Client::watch()`
3940
- :phpmethod:`MongoDB\\Collection::watch()`
41+
- :phpmethod:`MongoDB\\Database::watch()`
4042
- :php:`Iterator::next() <iterator.next>`
4143
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
4244
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBChangeStream-rewind.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ advanced).
4646
See Also
4747
--------
4848

49+
- :phpmethod:`MongoDB\\Client::watch()`
4950
- :phpmethod:`MongoDB\\Collection::watch()`
51+
- :phpmethod:`MongoDB\\Database::watch()`
5052
- :php:`Iterator::rewind() <iterator.rewind>`
5153
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
5254
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBChangeStream-valid.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ A boolean indicating whether there is a current event in the change stream.
3434
See Also
3535
--------
3636

37+
- :phpmethod:`MongoDB\\Client::watch()`
3738
- :phpmethod:`MongoDB\\Collection::watch()`
39+
- :phpmethod:`MongoDB\\Database::watch()`
3840
- :php:`Iterator::valid() <iterator.valid>`
3941
- :ref:`Tailable Cursor Iteration <php-tailable-cursor>`
4042
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBClient-watch.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble:
114114
See Also
115115
--------
116116

117+
- :phpmethod:`MongoDB\\Collection::watch()`
118+
- :phpmethod:`MongoDB\\Database::watch()`
117119
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
118120
the MongoDB Manual
119121
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBCollection-watch.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ script was iterating the change stream, the output would then resemble:
114114
See Also
115115
--------
116116

117+
- :phpmethod:`MongoDB\\Client::watch()`
118+
- :phpmethod:`MongoDB\\Database::watch()`
117119
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
118120
the MongoDB Manual
119121
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

source/reference/method/MongoDBDatabase-watch.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ script was iterating the change stream, the output would then resemble:
113113
See Also
114114
--------
115115

116+
- :phpmethod:`MongoDB\\Collection::watch()`
117+
- :phpmethod:`MongoDB\\Client::watch()`
116118
- :manual:`Aggregation Pipeline </core/aggregation-pipeline>` documentation in
117119
the MongoDB Manual
118120
- :manual:`Change Streams </changeStreams>` documentation in the MongoDB manual

0 commit comments

Comments
 (0)