Trigger cloud function when a specific condition resulting from the comparison of document fields in firestore is true

Viewed 96

In the observed document there are 2 fields that include timestamps, tsA and tsB. tsA moves progressively closer to tsB until they eventually are the same - when this happens a cloud function shall be triggered, which performs a database operation in Firestore. Is it possible to implement something like that - if so how?

1 Answers

No, you cannot trigger a function when a specific condition is met in Firestore. You can use onUpdate() trigger and then compare the values in the function itself.

If this operation doesn't need to be realtime then you can run a scheduled function (every few minutes/hours) that'll query for all documents where tsA and tsB are same and then process them.

Related