我目前有一个读取firestore的Google App Engine python脚本。结构如下
<collection name=Location1>
<document name=timestamp1>
data-array
<document name=timestamp2>
data-array
<document name=timestamp3>
data-array
<collection name=Location2>
<document name=timestamp1>
data-array
<document name=timestamp2>
data-array
<document name=timestamp3>
data-array
这基本上就是一个缓存。这最适合我的appengine,因为它动态地生成一个网页,所以它需要很快。它将位置作为输入,并尝试从“缓存”中提取过去12小时的数据。如果它不存在,它会从web中拉出丢失的数据并将其写入缓存。问题是我没有删除旧数据,也不能保证这个位置(集合)会再次被调用。我可以重新构造我的数据,使其具有包含位置文档的时间戳集合,但这会使查找数据变得困难。
因此,我想要一个单独的程序(云函数?)定期扫描我的firestore并从每个集合中删除任何超过X小时的内容,或者如果所有文档都较旧/已删除,则删除整个集合。我意识到我可能需要为每个文档添加一个时间戳条目,以便可以对其进行查询。
我所能找到的关于如何实现这一点的所有内容都是在https://firebase.google.com/docs/firestore/solutions/delete-collections上找到的,然而,我在理解它时遇到了问题,似乎需要我指定集合。
发布于 2020-06-22 23:19:55
Firestore没有任何内置的调度功能。你必须使用另一种产品来配合使用。
如果你已经在使用Google App Engine,你可以设置一个cron job,让它执行一个删除文档的程序。如果您更喜欢Cloud Functions,您可以使用Firebase scheduled function,或者如果您不使用Firebase工具,您可以通过配置Cloud Scheduler来调用您选择的HTTP端点来组合相同的功能。
https://stackoverflow.com/questions/62517014
复制相似问题