MongoChangeStreamCursor

The Mongo Cursor interface for change streams implementing the iterator protocol.

An application should ensure that a cursor is closed in all circumstances, e.g. using a use statement:

 collection.watch().cursor().use { c ->
while (c.hasNext()) {
println(c.next())
}
}

A com.mongodb.MongoOperationTimeoutException does not invalidate the MongoChangeStreamCursor, but is immediately propagated to the caller. Subsequent method calls will attempt to resume operation by establishing a new change stream on the server, without performing a getMore request first.

If a com.mongodb.MongoOperationTimeoutException occurs before any events are received, it indicates that the server has timed out before it could finish processing the existing oplog. In such cases, it is recommended to close the current stream and recreate it with a higher timeout setting.

Parameters

T

The type of documents the cursor contains

Functions

Link copied to clipboard
abstract override fun close()
Link copied to clipboard
open fun forEachRemaining(p0: Consumer<in T>)
Link copied to clipboard
abstract operator fun hasNext(): Boolean
Link copied to clipboard
abstract operator fun next(): T
Link copied to clipboard
abstract fun tryNext(): T?

A special next case that returns the next element in the iteration if available or null.

Properties

Link copied to clipboard
abstract val available: Int

Gets the number of results available locally without blocking, which may be 0.

Link copied to clipboard
abstract val resumeToken: BsonDocument?

Returns the resume token. If a batch has been iterated to the last change stream document in the batch and a postBatchResumeToken is included in the document, the postBatchResumeToken will be returned. Otherwise, the resume token contained in the last change stream document will be returned.

Link copied to clipboard
abstract val serverAddress: ServerAddress
Link copied to clipboard
abstract val serverCursor: ServerCursor?