Closed
Description
openedon Jan 31, 2024
Prerequisites
- I have written a descriptive issue title
Mongoose version
8.0.3
Node.js version
20.10.0
MongoDB version
6.0.13 (atlas server) & 6.2.0 (node)
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
Debian Bullseye 11
Issue
Hello, for some time now, some of my watchers have been disconnecting and not reconnecting, resulting in events not being received. I'm unable to reproduce the problem effectively locally, but once in production it often happens:
- I start my NodeJS service
- I start my watchers
- I log each insertion event
- After a while (sometimes 1 month or 10 days or less) I don't receive any more insertion events even though I'm creating documents.
Here is my current code :
const MyMongooseModel = mongoose.model('ModelName', mySchema);
MyMongooseModel.watch([{ $match: { operationType: "insert" } }])
.on("change", async data => {
console.log(data);
})
.on("error", error => {
console.error("Error on log watch stream", error);
});
--> How can I efficiently detect when watchers are completely closed in order to restart it ?
N.B. I've tried listening for the "close" event but sometimes it's sent but events are always received and sometimes afterwards there are no more events received.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment