Docs Menu
Docs Home
/ / /
PHP Library Manual
/ / /


On this page

  • Definition
  • Return Values
  • Examples
  • See Also

New in version 1.5.


Returns the cached resume token that will be used to resume the change stream.

function getResumeToken(): array|object|null

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.

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.

$uri = 'mongodb://,';
$collection = (new MongoDB\Client($uri))->test->inventory;
$changeStream = $collection->watch();
for ($changeStream->rewind(); true; $changeStream->next()) {
if ( ! $changeStream->valid()) {
$event = $changeStream->current();
if ($event['operationType'] === 'invalidate') {
$startAfter = $changeStream->getResumeToken();
printf("%d: %s\n", $changeStream->key(), $event['operationType']);
$changeStream = $collection->watch([], ['startAfter' => $startAfter]);
  • MongoDB\Client::watch()

  • MongoDB\Collection::watch()

  • MongoDB\Database::watch()

  • Resume a Change Stream documentation in the MongoDB manual

← getCursorId()
key() →