ChangeStreamIterable

class ChangeStreamIterable<T : Any>(wrapped: ChangeStreamIterable<T>) : MongoIterable<ChangeStreamDocument<T>>

Iterable like implementation for change streams.

Note: the ChangeStreamDocument class will not be applicable for all change stream outputs. If using custom pipelines that radically change the result, then the withDocumentClass method can be used to provide an alternative document format.

Parameters

T

The type of the result.

Constructors

Link copied to clipboard
constructor(wrapped: ChangeStreamIterable<T>)

Functions

Link copied to clipboard
open override fun batchSize(batchSize: Int): ChangeStreamIterable<T>

Sets the number of documents to return per batch.

Link copied to clipboard
fun collation(collation: Collation?): ChangeStreamIterable<T>

Sets the collation options

Link copied to clipboard
fun comment(comment: BsonValue?): ChangeStreamIterable<T>

Sets the comment for this operation. A null value means no comment is set.

Link copied to clipboard
open override fun cursor(): MongoChangeStreamCursor<ChangeStreamDocument<T>>

Returns a cursor used for iterating over elements of type {@code ChangeStreamDocument}. The cursor has a covariant return type to additionally provide a method to access the resume token in change stream batches.

Link copied to clipboard
fun first(): ChangeStreamDocument<T>
Link copied to clipboard
fun firstOrNull(): ChangeStreamDocument<T>?
Link copied to clipboard
fun forEach(action: (ChangeStreamDocument<T>) -> Unit)

Performs the given action on each element and safely closes the cursor.

Link copied to clipboard
fun fullDocument(fullDocument: FullDocument): ChangeStreamIterable<T>

Sets the fullDocument value.

Link copied to clipboard
fun fullDocumentBeforeChange(fullDocumentBeforeChange: FullDocumentBeforeChange): ChangeStreamIterable<T>

Sets the fullDocumentBeforeChange value.

Link copied to clipboard
fun <R> map(transform: (ChangeStreamDocument<T>) -> R): MongoIterable<R>

Maps this iterable from the source document type to the target document type.

Link copied to clipboard
fun maxAwaitTime(maxAwaitTime: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): ChangeStreamIterable<T>

Sets the maximum await execution time on the server for this operation.

Link copied to clipboard
fun resumeAfter(resumeToken: BsonDocument): ChangeStreamIterable<T>

Sets the logical starting point for the new change stream.

Link copied to clipboard

Sets whether to include expanded change stream events, which are: createIndexes, dropIndexes, modify, create, shardCollection, reshardCollection, refineCollectionShardKey. False by default.

Link copied to clipboard
fun startAfter(startAfter: BsonDocument): ChangeStreamIterable<T>

Similar to resumeAfter, this option takes a resume token and starts a new change stream returning the first notification after the token.

Link copied to clipboard
fun startAtOperationTime(startAtOperationTime: BsonTimestamp): ChangeStreamIterable<T>

The change stream will only provide changes that occurred at or after the specified timestamp.

Link copied to clipboard
fun <C : MutableCollection<in ChangeStreamDocument<T>>> toCollection(destination: C): C

Appends all elements to the given destination collection.

Link copied to clipboard
fun toList(): List<ChangeStreamDocument<T>>
Link copied to clipboard
fun <R> use(consumer: (Sequence<ChangeStreamDocument<T>>) -> R): R

Creates a new cursor and treats it as a Sequence, invokes the given consumer function and closes the cursor down correctly whether an exception is thrown or not.

Link copied to clipboard
fun <R : Any> withDocumentClass(resultClass: Class<R>): MongoIterable<R>

Returns a MongoIterable containing the results of the change stream based on the document class provided.