On this page本页内容
The following document represents all possible fields that a change stream response document can have.以下文档表示变更流响应文档可能具有的所有字段。
Some fields are only available for certain operations, such as updates. 某些字段仅适用于某些操作,例如更新。The following table describes each field in the change stream response document:下表描述了变更流响应文档中的每个字段:
| _id | document |
|
operationType |
| |
fullDocument |
document |
|
ns |
document | |
ns.db |
string | |
ns.coll |
string |
|
to |
document | operationType : rename, this document displays the new name for the ns collection. operationType : rename时,此文档显示ns集合的新名称。operationType.operationType的所有其他值,省略本文档。 |
to.db |
string | |
to.coll |
string | |
documentKey |
document | _id of the document created or modified by the insert, replace, delete, update operations (i.e. CRUD operations). insert、replace、delete、update操作(即CRUD操作)创建或修改的文档的_id的文档。_id field is not repeated if it is already a part of the shard key._id字段已经是碎片密钥的一部分,则不会重复该字段。 |
updateDescription |
document |
|
updateDescription.updatedFields |
document | |
updateDescription.removedFields |
array | |
clusterTime |
Timestamp |
|
txnNumber |
NumberLong |
|
lsid |
Document |
|
insert Event¶The following example illustrates an 以下示例演示了一个insert event:insert事件:
The documentKey field includes both the _id and the userName field. documentKey字段包括_id和userName字段。This indicates that the 这表明engineering.users collection is sharded, with a shard key on userName and _id.engineering.users集合是分片的,userName和_id上有一个分片键。
The fullDocument document represents the version of the document at the time of the insert.fullDocument文档表示插入时文档的版本。
updateThe following example illustrates an 以下示例演示了一个update event:update事件:
The following example illustrates an 以下示例演示了使用update event for change streams opened with the fullDocument : updateLookup option:fullDocument:updateLookup选项打开的更改流的update事件:
The fullDocument document represents the most current majority-committed version of the updated document. fullDocument文档代表更新文档的最新多数提交版本。The fullDocument document may vary from the document at the time of the update operation depending on the number of interleaving majority-committed operations that occur between the update operation and the document lookup.fullDocument文档可能与更新操作时的文档不同,具体取决于更新操作和文档查找之间发生的交错多数提交操作的数量。
replaceThe following example illustrates a 以下示例演示了一个replace event:replace事件:
A replace operation uses the update command, and consists of two stages:replace操作使用update命令,由两个阶段组成:
documentKey anddocumentKey删除原始文档,并且documentkeydocumentkey插入新文档The fullDocument of a replace event represents the document after the insert of the replacement document.replace事件的fullDocument表示插入替换文档后的文档。
delete Event¶The following example illustrates a 以下示例演示了一个delete event:delete事件:
The 当变更流游标向客户机发送fullDocument document is omitted as the document no longer exists at the time the change stream cursor sends the delete event to the client.delete事件时,由于文档不再存在,fullDocument文档被省略。
dropNew in version 4.0.1.版本4.0.1中新增。
A 从数据库中删除集合时会发生drop event occurs when a collection is dropped from a database. drop事件。The following example illustrates a 以下示例演示了一个drop event:drop事件:
A drop event leads to an invalidate event for change streams opened against its ns collection.drop事件导致针对其ns集合打开的更改流发生invalidate事件。
renameNew in version 4.0.1.版本4.0.1中新增。
A rename event occurs when a collection is renamed. rename集合时会发生重命名事件。The following example illustrates a 以下示例演示了rename event:rename事件:
A rename event leads to an invalidate event for change streams opened against its ns collection or to collection.rename事件会导致针对其ns集合或to集合打开的更改流的invalidate事件。
dropDatabaseNew in version 4.0.1.版本4.0.1中新增。
A 删除数据库时会发生dropDatabase event occurs when a database is dropped. dropDatabase事件。The following example illustrates a 以下示例演示了dropDatabase event:dropDatabase事件:
A 在为数据库生成dropDatabase command generates a drop event for each collection in the database before generating a dropDatabase event for the database.dropDatabase事件之前,dropDatabase命令会为数据库中的每个集合生成drop事件。
A dropDatabase event leads to an invalidate event for change streams opened against its ns.db database.dropDatabase事件会导致针对其ns.db数据库打开的更改流发生invalidate事件。
invalidateThe following example illustrates an 以下示例演示了一个invalidate event:invalidate事件:
For change streams opened up against a collection, a drop event, rename event, or dropDatabase event that affects the watched collection leads to an invalidate event.对于针对集合打开的更改流,影响监视的集合的drop事件、rename事件或dropDatabase事件会导致失效事件。
For change streams opened up against a database, a dropDatabase event that affects the watched database leads to an invalidate event.对于针对数据库打开的更改流,影响监视的数据库的dropDatabase事件会导致失效事件。
invalidate events close the change stream cursor.invalidate事件关闭更改流光标。
You cannot use 在resumeAfter to resume a change stream after an invalidate event (for example, a collection drop or rename) closes the stream. invalidate事件(例如,集合删除或重命名)关闭更改流后,不能使用resumeAfter恢复更改流。Starting in MongoDB 4.2, you can use startAfter to start a new change stream after an invalidate event.从MongoDB 4.2开始,可以使用startAfter在invalidate事件后启动新的更改流。