Overview
ChangeStreamContext<T> is the main runtime object passed to every handler method (@OnChange, @OnInsert, @OnUpdate, @OnDelete, @OnReplace). It provides access to the event metadata, documents, and runtime actions.
Document access
getFullDocument
Returns the full document after the operation, automatically converted to the requested type using Spring’sMongoConverter.
DELETE operations, the full document is not available and the method returns Optional.empty().
getFullDocumentBeforeChange
Returns the document before the operation, automatically converted using Spring’sMongoConverter. This is useful for comparing old vs. new state (e.g., audit logging, status transition tracking).
@ChangeStream annotation controls how pre-images are requested:
fullDocumentBeforeChange | Behavior if pre-images are not enabled on collection |
|---|---|
OFF (default) | No pre-image requested. getFullDocumentBeforeChange() always returns Optional.empty(). |
WHEN_AVAILABLE | Returns Optional.empty() silently. Safe for optional use cases. |
REQUIRED | MongoDB returns an error and the event processing fails. Use when pre-images are mandatory. |
getUpdateDescription
ForUPDATE operations, returns the list of updated and removed fields.
Event metadata
| Method | Returns | Description |
|---|---|---|
getEventId() | String | Unique ID generated by FlowWarden for this event |
getOperationType() | OperationType | INSERT, UPDATE, REPLACE, DELETE, DROP, INVALIDATE |
getStreamName() | String | Name of the @ChangeStream handler |
getCollectionName() | String | Source MongoDB collection |
getDatabaseName() | String | Source MongoDB database |
getClusterTime() | Instant | MongoDB cluster timestamp |
getResumeToken() | BsonDocument | Resume token for checkpointing |
getDocumentKey() | BsonValue | The _id of the affected document |
getAttemptNumber() | int | Current retry attempt (1-based) |

