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

查看:81
本文介绍了如何为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中没有内置的生存时间机制消防站。常见的方法是每隔一段时间运行一段代码,例如

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.

看看这些样本问题:

  • Delete firebase data older than 2 hours
  • How to delete firebase data after "n" days
  • Impelementing aging in a Firebase real time database
  • How to schedule a Cloud Functions to run in the future in order to build a Firestore document TTL

尽管这些用于Firebase实时数据库,但相同的方法也适用于Cloud Firestore。

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

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

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