I have an aggregation pipeline ending with a $merge stage.
db.collection("mycoll").aggregate([..., {$merge:{into:"myview"}}])
I have to generate materialized views at run-time and keep them up-to-date with changes.
The issue I’m facing is that if the $merge has not completed yet and I try to run an update on the target collection it will only update the documents that were already merged, while the rest gets inserted with outdated values.
In order to fix this, I would need to delay or prevent updates while the merge is running.
I can’t seem to find a way to know when the merge has completed.
The cursor returned by the aggregate is empty when using $merge so I can’t keep track using the cursor.
Looking at currentOp doesn’t seem to show the aggregate with the $merge only showing the individual updates of each document that the merge is doing.
How can I know when the merge is done ?