How to get changed data with replace operation in change data streams

Hi All,

How do we get document “deltas” (changed data) with replace operation from change data streams on a collection.

Thanks in advance

Hi @Sundar_Koduru,

You can check the docs of change events here -

According to this, the “fullDocument” contains the changes for an “insert” and “replace” operation. I don’t think you would need to enable the full Document on the change stream for these operations, only for updates. Hence, for replace operations, this is where you will get the changed document by default.

If you want the delta of changes from original to newer, you would need to implement this yourself somehow, as I don’t think Mongo can provide the delta of an “replace” operation. It just takes the newer doc fully and replaces it, without seeing what changed. You might want to store the previous document in some cache and check the change urself for replaces.