Replies: 3 comments 13 replies
-
@thaoula can you please provide the code snippet you used to repro this behavior? |
Beta Was this translation helpful? Give feedback.
-
I am facing the same problem. There is no absolute solution to this at least in mongoose. I have to try the native nodejs driver |
Beta Was this translation helpful? Give feedback.
-
We have faced such issues with MongoDB Change Streams while using MongoDB Atlas. This especially happens during a MongoDB Atlas scheduled maintenance. Change Streams were paused silently - No errors were reported! We had all resuming logic in place where in case of error/close/end events we wanted to resume the change streams, but to our surprise, during the Atlas scheduled maintenance we never received error/close/end events on change streams! To overcome with these issues, we decided to "Rewatch & Resume" on server election events as well - when Primary Node is changed! I have implemented a Change Stream Wrapper : https://gist.github.com/rahulbhooteshwar/8e72c9f5c17e27cf69fd1fb6c2e015a4 It takes care of following:
|
Beta Was this translation helpful? Give feedback.
-
Hi All,
We are trying to utilise ChangeStreams using Mongoose and have encountered some challenges with reliability.
We have the following issues:
For some unknown reason, our DB level ChangeStream which is connected to an Atlas Cluster stops receiving changes. We do not get any errors even though we are using ChangeStream.on('error') listener. Nothing is logged.
When this happens, restarting the container but keeping the resume token i.e we are setting resumeAfter does not work. We only get changes after deleting the resume token and restarting the container.
Before logging some Github issues I wanted to see if anyone has experienced problems like this and whether you have some tips.
What Works
For some unknown reason (maybe low activity due to weekend or overnight, or primary changes), the change stream stops receiving change events. I am not sure how to debug this issue as no event listeners are called on the change stream. ie. error, resumeTokenChanged, closed events are never ever triggered.
By chance after reviewing the mongoose code and noticing the returned changestream was a wrapped object, I decided to just use connection.getClient().watch which returns a mongdb native ChangeStream and I am able to successfully listen to resumeTokenChanged, closed, change and error events as I would have expected when using connection.watch().
When using this approach, I suprisingly found that the resumeTokenChanged event is called almost once per second and the token is changing. Also, the token returned by this event is also much shorter than the resume token that is provided in the change event.
I also noticed that if i stop the database (test failure) the change stream is closed (it calls the close event listener) and it is able to resume when i restart the database server.
My questions are -
Sorry for the all the questions.
Regards,
Tarek
Beta Was this translation helpful? Give feedback.
All reactions