0

Suppose I have a Firestore document and has a Date/Time Field called "AlarmTime" which holds some future Date/Time value.

Q1: Is there a way to tell Firestore to Trigger an event when any document's "AlarmTime" matches Current Time, so we can respond to that trigger event in a Cloud function?

Q2: If that is not possible, what would be the most efficient way in a Cloud Function to find any document's that it's "AlarmTime" field has reached the current time? I would find it inefficient to Poll the database continuously.

Thank you in advance! ..Ben

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Ben Hayat
  • 49
  • 6

1 Answers1

2

A1: It's not possible.

A2: You could consider scheduling a callback to another function on a delay. You would have to schedule this at the time the field is being written, and you would have to compute the time in the future you want to be notified that the document should be deleted. Cloud Tasks can do that for you. The implementation to get that all set up is nontrivial and too long to outline here, but it's possible. Also consider anything discussed here: Cloud Functions for Firebase trigger on time?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Hey Doug, thank you for the reply. You're always helpful. I didn't know about the Cloud task. Need to look into it. Thanks again ..Ben – Ben Hayat Mar 05 '19 at 01:41