0

So I want to make a loop that keeps checking the database and make action if something has changed.

What i'm trying to make is somewhat like a mute system in mongodb. Where I give records an expiry date of the mute length. Which I already did with creating an index option called expireAfterSeconds. But my problem is I want to make a python script to keep check if the record has expired with using less memory & cpu resources of making mongodb queries.

I have an idea (inefficient solution) and I think it can work but I think it's inefficient because it uses a lot of mongodb queries. And my solution is to make a while loop in python that keeps making mongodb queries to check if the record has expired or not.

But is there any other solutions that doesn't use a lot of queries or making a loop? And I'm not that good with event driven loops so can someone suggest me another solution to this or should I just stick to my solution?

Sorry for my bad explanation I hope someone can get it. Thanks.

0jxf
  • 1
  • 2
  • what do you want to do if it is expired? this may help https://docs.mongodb.com/manual/tutorial/expire-data/ – deadshot Jul 24 '21 at 20:40
  • This works fine but I want to make an action in python if the record has been expired. – 0jxf Jul 24 '21 at 20:45
  • "I want to make an action in python" can you be more specific – deadshot Jul 24 '21 at 20:46
  • So if the record got deleted from mongodb then I want python to execute a function to do something and indicate or print that this record has been expired – 0jxf Jul 24 '21 at 20:48
  • this will help pymongo [change_stream](https://stackoverflow.com/questions/9691316/how-to-listen-for-changes-to-a-mongodb-collection) – deadshot Jul 24 '21 at 20:53
  • 1
    This definitely may be what I'm looking for. I'm gonna close this question if it worked with me. Thanks! – 0jxf Jul 24 '21 at 21:01

0 Answers0