- Reference >
- Operators >
- Aggregation Pipeline Stages >
- $changeStream (aggregation)
$changeStream (aggregation)¶
On this page
Definition¶
-
$changeStream¶ Returns a Change Stream cursor on a collection, a database, or an entire cluster. Must be used as the first stage in an aggregation pipeline.
The
$changeStreamstage has the following syntax:Parameter Description allChangesForClusterOptional: Sets whether the change stream should include all changes in the cluster. May only be opened on the admindatabase.fullDocumentOptional: Specifies whether change notifications include a copy of the full document when modified by
updateoperations.default: Change notifications do not include the full document forupdateoperations.updateLookup: Change notifications includes a copy of the document modified by the change. This document is the current majority-committed document ornullif it no longer exists.
In the case of partial updates, the change notification also provides a description of the change.
resumeAfterSpecifies a resume token as the logical starting point for the change stream. Cannot be used with startAfterorstartAtOperationTimefields.startAfterSpecifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfterorstartAtOperationTimefields.startAtOperationTimeSpecifies a time as the logical starting point for the change stream. Cannot be used with resumeAfterorstartAfterfields.
Examples¶
To create a change stream cursor using the aggregation stage, run
the aggregate command.
When the change stream detects a change, the next() method returns a change
event notification. For example:
For more information on change stream notifications, see Change Events