如何为 Firestore 创建自动删除机制?(时间段后删除数据) [英] How to create an auto delete mechanism for firestore? (deleting data after time period)

查看:21
本文介绍了如何为 Firestore 创建自动删除机制?(时间段后删除数据)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何开始/完成此操作,如果文档在特定时间段(例如 30 天)内未更改或访问,我希望 Firestore 数据库中的集合中的文档自行删除.换句话说,如果不需要,数据应该过期(被删除).

I am not sure how to start/accomplish this, I am want the documents in a collection in a firestore database to delete themselves if the document was not changed or accessed for a certain time period (for example 30 days). In other words, the data should expire (be removed) if not needed.

有什么办法可以完成这个任务吗?

Is there any way to accomplish this task?

感谢您的帮助!

推荐答案

Cloud Firestore 中没有内置的生存时间机制.常见的方法是每隔一段时间运行一段代码,例如由 cron-job.org 之类的东西触发的云函数.

There is no built-in time-to-live mechanism in Cloud Firestore. The common approach is to run a piece of code at an interval, e.g. a Cloud Function triggered by something like cron-job.org.

看看样本的这些问题:

虽然这些适用于 Firebase 实时数据库,但同样的方法也适用于 Cloud Firestore.

While these are for the Firebase Realtime Database, the same approach applies to Cloud Firestore.

这篇关于如何为 Firestore 创建自动删除机制?(时间段后删除数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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