| 前提 | 复制集或分片集群 |
|---|---|
| 语法 | db.coll.watch(pipeline, options) |
| 事件 | operationType / documentKey / fullDocument / updateDescription |
mongosh 示例
mongosh 示例
const cs = db.orders.watch([{ $match: { "operationType": "insert" } }])
cs.on("change", (ev) => printjson({ key: ev.documentKey, doc: ev.fullDocument }))应用侧可用 resumeAfter 传入上次 token 断点续传;变更流受 oplog 保留窗口限制,长时间断连可能无法追赶。