Reacting to Changes
A change stream lets an application subscribe to a real time feed of inserts, updates, deletes, and other events on a collection, database, or whole deployment. Instead of polling, the app receives events as they happen.
How It Works
Change streams read from the replica set oplog, the operational log that records every write. Because they use the oplog, they require a replica set or sharded cluster.
- Each event includes the operation type and the affected document or its key.
- A resume token marks your position, so you can reconnect and continue without missing events.
- Events are delivered in a total order consistent with majority committed writes.
Common Uses
- Driving cache invalidation when source data changes.
- Feeding search indexes or analytics in near real time.
- Triggering notifications and downstream workflows.
Because change streams only surface majority committed changes, the events you receive will not be rolled back later.
Key idea
Change streams deliver a resumable real time feed of majority committed changes from the oplog, replacing polling for cache invalidation, indexing, and triggers.