如何让Firebase自动删除超过30分钟的值 [英] How to have Firebase automatically delete values older than 30 minutes
问题描述
buyer_name:john@gmail.com
seller_name:tom@gmail.com
价格:20.00
产品:棒球卡
时间戳:1498677314931
我正在用
来获取时间戳FIRServerValue.timestamp()
我想创建某种类型的超时,按照时间戳删除超过30分钟的Firebase数据。问题是,我不想直接从应用程序,因为用户可以在技术上5分钟后注销。我想从其他一些独立的过程来做。
所以,我想知道是否可以通过Firebase自动完成,或者如果我必须部署其他应用程序在EC2实例上持续执行此操作,或者有其他方法吗?
您可以使用Cloud Functions for Firebase并建立一个cron作业,每五分钟运行一次,并检查超过30分钟的时间戳。
正如Will评论的那样,这篇博客文章对于了解调度云功能。这里有一些其他有用的资源,让你开始:
noreferrer>使用HTTP触发器和Cron为Firebase定时云端功能
I have a Swift/iOS application that creates/holds data something like this:
buyer_name: "john@gmail.com"
seller_name: "tom@gmail.com"
price: "20.00"
product: "baseball cards"
timestamp: 1498677314931
I am taking the timestamp with
FIRServerValue.timestamp()
I would like to create some kind of timeout, where it deletes firebase data older than 30 minutes, as per the timestamp. The problem is that I would not like to do it directly from the app, as the user could technically logout after 5 minutes. I would like to do it from some other independent process.
So, I'm wondering if this can be done automatically through Firebase, or if I have to deploy some other application that does this continuously on an EC2 instance, or if there is some other method?
You can use Cloud Functions for Firebase and set up a cron job that runs, say, every five minutes and checks for timestamps older than 30 minutes.
As Will commented, that blog post is useful to learn about scheduling Cloud Functions. Here are some other useful resources to get you started:
Getting Started with Cloud Functions for Firebase - YouTube
Cloud Functions for Firebase Documentation
Timing Cloud Functions for Firebase using an HTTP Trigger and Cron - YouTube
这篇关于如何让Firebase自动删除超过30分钟的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!