Change streams watch collections, databases, or deployments for changes.
When a change occurs on a watched resource, the change stream returns a change event notification document, with information on the operation and the changes it made.
Operation Types
Event | Description | |
---|---|---|
showExpandedEvents option to New in version 6.0. | ||
Occurs when an index is dropped from the collection. Requires that you set the | Occurs when an operation renders the change stream invalid. | |
Occurs when a collection is renamed. | ||
Occurs when an update operation removes a document from a collection and replaces it with a new document. | ||
Occurs when the shard key for a collection and the distribution of data changes. Requires that you set the | Occurs when an operation updates a document in a collection. |
Note
The server might internally process and return update operations as replace operations if the representation of replace operations are more concise. If you are listening for update operations, we strongly recommend also listening for replace operations.
Resume Token
Each change event includes an _id
field, which contain a document. This
document can serve as the resume token when
starting a change stream.
Expanded Events
New in version 6.0.
Starting in MongoDB 6.0, change streams support change notifications for DDL
events, like the createIndexes and
dropIndexes events. To include expanded
events in a change stream, create the change stream cursor using the
showExpandedEvents
option.
For example:
let cur = db.names.aggregate( [ { $changeStream: { showExpandedEvents: true } } ] ) cur.next()
Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!
Check out: eBank.nz (Art Generator) |
Netwrck.com (AI Tools) |
Text-Generator.io (AI API) |
BitBank.nz (Crypto AI) |
ReadingTime (Kids Reading) |
RewordGame |
BigMultiplayerChess |
WebFiddle |
How.nz |
Helix AI Assistant