How to keep a stable connection and handle error using changeStream?

I am using Change Stream[]).on("change", 
    (data) => {console.log(data)})

in my multiple applications to track my database changes.

May I ask how can I add re-connect to the server when I faced any type of connection issue. Is there any auto-retry mechanism or standard way for doing this?

Hi @WONG_TUNG_TUNG and welcome to MongoDB community forums!!

The connection pool mechanism manages the connections between the applications and the MongoDB instances.
You can read the documentation on how to configure the connection pooling for your application for further understanding.

To further understand the concern could you help me understand the error message you have been facing with the connections and the need for re-connecting? It would be further helpful if you could help with the error message or a scenario/use case where you are facing the connection issues.