4

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.

auntyellow
  • 2,423
  • 2
  • 20
  • 47
  • 1
    In the findAndModify command you have an option to specify (new : true/false) whether you return the new version (true) or the original version of the document (false, this is the default) – Dexter Aug 29 '19 at 05:49

2 Answers2

6

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.

Rajat Goel
  • 2,207
  • 17
  • 35
  • 1
    That's unfortunate. Though they are working on it (https://jira.mongodb.org/browse/SERVER-36941), it should have been from the start so that it's more useful. – ian Feb 09 '22 at 01:44
-1

In the findAndModify command you have an option to specify (new : true/false) whether you return the new version (true) or the original version of the document (false, this is the default)

Dexter
  • 831
  • 8
  • 17
  • Can you give an example? We are talking about **Change Stream** (What is new in MongoDB 3.6) but not simple update / modify. – auntyellow Aug 29 '19 at 08:56