如何为 Firestore 创建自动删除机制?(时间段后删除数据) [英] How to create an auto delete mechanism for firestore? (deleting data after time period)
问题描述
我不确定如何开始/完成此操作,如果文档在特定时间段(例如 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.
看看样本的这些问题:
- 删除超过 2 小时的 Firebase 数据
- 如何在n"之后删除 firebase 数据天
- 在 Firebase 实时数据库中实施元素老化
- 如何安排 Cloud Functions 将来运行以构建 Firestore 文档 TTL
虽然这些适用于 Firebase 实时数据库,但同样的方法也适用于 Cloud Firestore.
While these are for the Firebase Realtime Database, the same approach applies to Cloud Firestore.
这篇关于如何为 Firestore 创建自动删除机制?(时间段后删除数据)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!