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
文档表示插入时文档的版本。
update
The 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
文档可能与更新操作时的文档不同,具体取决于更新操作和文档查找之间发生的交错多数提交操作的数量。
replace
The following example illustrates a 以下示例演示了一个replace
event:replace
事件:
A replace
operation uses the update command, and consists of two stages:replace
操作使用update
命令,由两个阶段组成:
documentKey
anddocumentKey
删除原始文档,并且documentkey
documentkey
插入新文档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
文档被省略。
drop
New 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
事件。
rename
New 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
事件。
dropDatabase
New 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
事件。
invalidate
The 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
事件后启动新的更改流。