Aggregation pipeline update is reported as 'replace' instead of 'update'

Hi all,

I am working on a project where I update the DB and listen for changes with the change streams. I frequently update a document’s nested fields and do it conditionally using the aggregation pipeline update. However, when this change in the DB is reported via the change stream its operationType is set to ‘replace’ instead as ‘update’. I’m doing the update with findOneAndUpdate.

Is there any chance to use the aggregation pipeline for conditional update and also get this change reported as ‘update’ to access the updated and removed fields?

Regards,
Ventsi

Hello @Ventsislav_Staykov, welcome to the MongoDB Community forum!

It looks like (I tried some code using MongoDB v4.2.8 cluster) all the update operations (updateOne, findAndModify, findOneAndUpdate, etc.) report the update’s change stream operation type as "replace" when the update is an Update with Aggregation Pipeline.

Yes, it seems so. Unfortunately, I cannot see how to use this powerful combination. Thanks for sharing your observations.

Hi @Ventsislav_Staykov, and welcome to the forums!

As @Prasad_Saya has pointed out, as of current stable version of MongoDB server (v4.4) an update operation with an aggregation pipeline expression will show up as replace operationType.

Depending on the use case, if you’re interested to keep track of historical changes of a document, perhaps you could add a field to keep track of document versions and insert a new version of the document.

Regards,
Wan.

Hi, this is very unfortunate. Has this behavior changed in v5.0? Will it ever change?
Thank you,
Manuel