I have an app that uses MongoDB via mongoose. On the app there is a collection called Notifications
. I would like to detect every time there is a change in that collection(including deleting a document) and take the appropriate action. I have read here that:
Like Model.remove(), this function (Model.findOneAndDelete(), Model.deleteOne()), does not trigger pre('remove') or post('remove') hooks.
I have then read here that:
Change streams provide a way for you to listen to all inserts and updates going through your MongoDB database. Note that change streams do not work unless you're connected to a MongoDB replica set.
Does change streams consider deletions as updates? How can I listen to all changes in a db including the deletion of a document?