Interface ChangeStreamPublisher<TResult>

Type Parameters:
TResult - The type of the result.
All Superinterfaces:
Publisher<ChangeStreamDocument<TResult>>

public interface ChangeStreamPublisher<TResult> extends Publisher<ChangeStreamDocument<TResult>>
Iterable for change streams.
Since:
1.6
Since server release
3.6
  • Method Details

    • fullDocument

      ChangeStreamPublisher<TResult> fullDocument(FullDocument fullDocument)
      Sets the fullDocument value.
      Parameters:
      fullDocument - the fullDocument
      Returns:
      this
    • fullDocumentBeforeChange

      ChangeStreamPublisher<TResult> fullDocumentBeforeChange(FullDocumentBeforeChange fullDocumentBeforeChange)
      Sets the fullDocumentBeforeChange value.
      Parameters:
      fullDocumentBeforeChange - the fullDocumentBeforeChange
      Returns:
      this
      Since:
      4.7
      Since server release
      6.0
    • resumeAfter

      ChangeStreamPublisher<TResult> resumeAfter(BsonDocument resumeToken)
      Sets the logical starting point for the new change stream.
      Parameters:
      resumeToken - the resume token
      Returns:
      this
    • startAtOperationTime

      ChangeStreamPublisher<TResult> startAtOperationTime(BsonTimestamp startAtOperationTime)
      The change stream will only provide changes that occurred after the specified timestamp.

      Any command run against the server will return an operation time that can be used here.

      The default value is an operation time obtained from the server before the change stream was created.

      Parameters:
      startAtOperationTime - the start at operation time
      Returns:
      this
      Since:
      1.9
      MongoDB documentation
      reference/method/db.runCommand/
      Since server release
      4.0
    • startAfter

      ChangeStreamPublisher<TResult> startAfter(BsonDocument startAfter)
      Similar to resumeAfter, this option takes a resume token and starts a new change stream returning the first notification after the token.

      This will allow users to watch collections that have been dropped and recreated or newly renamed collections without missing any notifications.

      Note: The server will report an error if both startAfter and resumeAfter are specified.

      Parameters:
      startAfter - the startAfter resumeToken
      Returns:
      this
      Since:
      1.12
      MongoDB documentation
      changeStreams/#change-stream-start-after
      Since server release
      4.2
    • maxAwaitTime

      ChangeStreamPublisher<TResult> maxAwaitTime(long maxAwaitTime, TimeUnit timeUnit)
      Sets the maximum await execution time on the server for this operation.
      Parameters:
      maxAwaitTime - the max await time. A zero value will be ignored, and indicates that the driver should respect the server's default value
      timeUnit - the time unit, which may not be null
      Returns:
      this
    • collation

      Sets the collation options

      A null value represents the server default.

      Parameters:
      collation - the collation options to use
      Returns:
      this
    • withDocumentClass

      <TDocument> Publisher<TDocument> withDocumentClass(Class<TDocument> clazz)
      Returns a MongoIterable containing the results of the change stream based on the document class provided.
      Type Parameters:
      TDocument - the result type
      Parameters:
      clazz - the class to use for the raw result.
      Returns:
      the new Mongo Iterable
    • batchSize

      ChangeStreamPublisher<TResult> batchSize(int batchSize)
      Sets the number of documents to return per batch.

      Overrides the Subscription.request(long) value for setting the batch size, allowing for fine-grained control over the underlying cursor.

      Parameters:
      batchSize - the batch size
      Returns:
      this
      Since:
      1.8
      MongoDB documentation
      Batch Size
    • first

      Helper to return a publisher limited to the first result.
      Returns:
      a Publisher which will contain a single item.
      Since:
      1.8
    • comment

      Sets the comment for this operation. A null value means no comment is set.
      Parameters:
      comment - the comment
      Returns:
      this
      Since:
      4.6
      Since server release
      3.6
    • comment

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

      The comment can be any valid BSON type for server versions 4.4 and above. Server versions between 3.6 and 4.2 only support string as comment, and providing a non-string type will result in a server-side error.

      Parameters:
      comment - the comment
      Returns:
      this
      Since:
      4.6
      Since server release
      3.6
    • showExpandedEvents

      ChangeStreamPublisher<TResult> showExpandedEvents(boolean showExpandedEvents)
      Sets whether to include expanded change stream events, which are: createIndexes, dropIndexes, modify, create, shardCollection, reshardCollection, refineCollectionShardKey. False by default.
      Parameters:
      showExpandedEvents - true to include expanded events
      Returns:
      this
      Since:
      4.7
      Since server release
      6.0