Documentation

ChangeStream
in package
implements Iterator

Iterator for a change stream.

Tags
see
Collection::watch()
see
https://mongodb.com/docs/manual/reference/method/db.watch/#mongodb-method-db.watch
psalm-type

ResumeCallable = callable(array|object|null, bool): ChangeStreamIterator

template-implements

Table of Contents

Interfaces

Iterator

Constants

CURSOR_NOT_FOUND  = 43
RESUMABLE_ERROR_CODES  = [ 6, // HostUnreachable 7, // HostNotFound 89, // NetworkTimeout 91, // ShutdownInProgress 189, // PrimarySteppedDown 262, // ExceededTimeLimit 9001, // SocketException 10107, // NotPrimary 11600, // InterruptedAtShutdown 11602, // InterruptedDueToReplStateChange 13435, // NotPrimaryNoSecondaryOk 13436, // NotPrimaryOrSecondary 63, // StaleShardVersion 150, // StaleEpoch 13388, // StaleConfig 234, // RetryChangeStream 133, ]
WIRE_VERSION_FOR_RESUMABLE_CHANGE_STREAM_ERROR  = 9

Properties

$codec  : DocumentCodec|null
$hasAdvanced  : bool
Whether the change stream has advanced to its first result. This is used to determine whether $key should be incremented after an iteration event.
$iterator  : ChangeStreamIterator
$key  : int
$resumeCallable  : ResumeCallable|null

Methods

current()  : array<string|int, mixed>|object|null
getCursorId()  : Int64
getResumeToken()  : array<string|int, mixed>|object|null
Returns the resume token for the iterator's current position.
key()  : int|null
next()  : void
rewind()  : void
valid()  : bool
isResumableError()  : bool
Determines if an exception is a resumable error.
onIteration()  : void
Perform housekeeping after an iteration event.
resume()  : void
Recreates the ChangeStreamIterator after a resumable server error.
resumeOrThrow()  : void
Either resumes after a resumable error or re-throws the exception.

Constants

RESUMABLE_ERROR_CODES

private mixed RESUMABLE_ERROR_CODES = [ 6, // HostUnreachable 7, // HostNotFound 89, // NetworkTimeout 91, // ShutdownInProgress 189, // PrimarySteppedDown 262, // ExceededTimeLimit 9001, // SocketException 10107, // NotPrimary 11600, // InterruptedAtShutdown 11602, // InterruptedDueToReplStateChange 13435, // NotPrimaryNoSecondaryOk 13436, // NotPrimaryOrSecondary 63, // StaleShardVersion 150, // StaleEpoch 13388, // StaleConfig 234, // RetryChangeStream 133, ]

WIRE_VERSION_FOR_RESUMABLE_CHANGE_STREAM_ERROR

private mixed WIRE_VERSION_FOR_RESUMABLE_CHANGE_STREAM_ERROR = 9

Properties

$hasAdvanced

Whether the change stream has advanced to its first result. This is used to determine whether $key should be incremented after an iteration event.

private bool $hasAdvanced = false

$resumeCallable

private ResumeCallable|null $resumeCallable

Methods

getCursorId()

public getCursorId() : Int64
Return values
Int64

getResumeToken()

Returns the resume token for the iterator's current position.

public getResumeToken() : array<string|int, mixed>|object|null

Null may be returned if no change documents have been iterated and the server did not include a postBatchResumeToken in its aggregate or getMore command response.

Return values
array<string|int, mixed>|object|null

onIteration()

Perform housekeeping after an iteration event.

private onIteration(bool $incrementKey) : void
Parameters
$incrementKey : bool

Increment $key if there is a current result

Tags
throws
ResumeTokenException

resume()

Recreates the ChangeStreamIterator after a resumable server error.

private resume() : void

resumeOrThrow()

Either resumes after a resumable error or re-throws the exception.

private resumeOrThrow(RuntimeException $exception) : void
Parameters
$exception : RuntimeException
Tags
throws
RuntimeException

        
On this page

Search results