How to set timeout in change stream

I am working on some realtime data update application so in that I am thinking to use change stream to get the realtime db updates but while setting up change stream, I am unable to find any way by which I can set timeout for the change stream. I need timeout because if there will be no update in db then it will keep blocking further execution of the code. Is there any way by which this can be achieved?

Thanks in advance!!

Drivers may support timeout feature, here’s one example for nodejs

Thanks for you help @Kobe_W. I am using Python for my implementation. I thought of one solution by using thread to start change stream in background and set timeout for that thread, so once the thread timed out, change stream will not block further code. I am not sure whether this is good implementation or not. It will be a great help if you put some light on it.

https://pymongo.readthedocs.io/en/4.3.3/api/pymongo/change_stream.html

1 Like