Count down a field and trigger an action

Hello, I am developing a reminder of meeting by mongodb and golang. The basic idea is to create a meeting in mongo, then count down on the “due date” of the meeting, and just before 2 hours of the meeting, mongodb can trigger a function in golang and then golang function can send email or sms to user. Is it possible to use some timer-like module in mongo to do the “count down” on a time field? Thanks.

Hi @Zhihong_GUO,

It sounds like you will benefit from a trigger on our Atlas platform if you store your data in an Atlas cluster ( most recommended way to run MongoDB)

Your scheduled trigger can be triggered every minute and query on the reminderThresholdfield gathering all data for reminding users and since this is a serverless function you can use it to send SMS via Twilio or Emails via 3rd party or AWS SES …

If you cannot use Atlas you may need to write the scheduled process yourself.

A creative way might be to define a 0 expireAfterSeconds TTL index on a field holding the time of reminder and then have a change streams on this delete triggering the alerts, but it might be a serious overkill and complicated way…

Best
Pavel

Hello Pavel,

Many thanks for the answer. I don’t use Atlas for the time being so I can choose the second or the 3rd way mentioned by your answer. As to the “scheduled process”, you mean I should write the schedule process by golang, like to build a process by gocron? or there is a way in mongodb to write the schedule process then trigger the function “send sms or email” in golang?

James

Hi @Zhihong_GUO,

The platform you decide to build.your own triggers upon is your choice. There is no triggering mechanism in the MongoDB server other than ttl deletes.

If you wish to file a feature request consider placing one at https://feedback.mongodb.com

Thanks
Pavel