Change Events更改事件
On this page
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操作类型
create | Requires that you set the showExpandedEvents option to true. showExpandedEvents选项设置为true。New in version 6.0. |
createIndexes | true. showExpandedEvents选项设置为true。New in version 6.0. |
delete | |
drop | New in version 4.0.1. |
dropDatabase | New in version 4.0.1. |
dropIndexes | true. showExpandedEvents选项设置为true。New in version 6.0. |
insert | |
invalidate | |
modify | true. showExpandedEvents选项设置为true。New in version 6.0. |
rename | New in version 4.0.1. |
replace | |
shardCollection | true. showExpandedEvents选项设置为true。New in version 6.0. |
update |
Resume Token恢复令牌
Each change event includes an 每个更改事件都包括一个_id field, which contain a document. _id字段,其中包含一个文档。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. 从MongoDB 6.0开始,更改流支持DDL事件的更改通知,如createIndexes和dropIndexes事件。To include expanded events in a change stream, create the change stream cursor using the 要在变更流中包括展开的事件,请使用showExpandedEvents option.showExpandedEvents选项创建变更流游标。
For example:例如:
let cur = db.names.aggregate( [ {
$changeStream: {
showExpandedEvents: true
}
}
] )
cur.next()