当文档的“日期/时间"字段与当前时间匹配时,我们如何让Firestore触发事件? [英] How can we get Firestore to trigger an event when a document's Date/Time field matches current time?

查看:45
本文介绍了当文档的“日期/时间"字段与当前时间匹配时,我们如何让Firestore触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个Firestore文档,并且有一个名为"AlarmTime"的日期/时间"字段,其中包含一些将来的日期/时间"值.

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

问题1:是否有一种方法可以告诉Firestore在任何文档的"AlarmTime"与当前时间匹配时触发事件,以便我们可以在Cloud函数中响应该触发事件?

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?

第二季度:如果不可能,那么在Cloud Function中找到"AlarmTime"字段已达到当前时间的任何文档的最有效方法是什么?我发现连续轮询数据库效率低下.

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.

先谢谢您!..Ben

Thank you in advance! ..Ben

推荐答案

A1:这不可能.

A2:您可以考虑将延迟调度到另一个函数.您将必须在写入字段时安排此时间,并且必须计算将来要通知您应该删除文档的时间. Cloud Tasks 可以为您做到这一点.实现所有设置的实现是不平凡的,并且在这里概述太短,但这是可能的.还考虑此处讨论的任何内容: Firebase的云功能是否按时触发?

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?

这篇关于当文档的“日期/时间"字段与当前时间匹配时,我们如何让Firestore触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆