简体   繁体   中英

MongoDB Change Stream: Can I get value before update/delete?

Change Stream Event on an update operation just return the document that changes to, same as oplog. Can I get the document (or some updated values) before update?

MySQL row-based binlog can do this with full binlog_row_image.

No, from change stream an update event looks like:

{
   _id: { < Resume Token > },
   operationType: 'update',
   clusterTime: <Timestamp>,
   ns: {
      db: 'engineering',
      coll: 'users'
   },
   documentKey: {
      _id: ObjectId("58a4eb4a30c75625e00d2820")
   },
   updateDescription: {
      updatedFields: {
         email: 'alice@10gen.com'
      },
      removedFields: ['phoneNumber']
   }
}

Only the new values are present, unlike MySQL where you get both after and before.

在findAndModify命令中,您可以选择指定(new:true / false)是返回新版本(true)还是文档的原始版本(false,这是默认值)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM