Firebase Firestore 中的文档是否有任何 TTL(生存时间) [英] Is there any TTL (Time To Live ) for Documents in Firebase Firestore

查看:26
本文介绍了Firebase Firestore 中的文档是否有任何 TTL(生存时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firebase Firestore 的文档是否有任何 TTL 选项.在那段时间之后文档被自动删除

解决方案

没有这样的内置功能.<​​/p>

自己构建它的最简单方法是:

  1. 向您的文档添加 expirationTimestamp 属性.
  2. 拒绝读取在您的安全规则中已过期的文档.

    match/collection/{document} {允许读取:如果 resource.data.expirationTimestamp >request.time.date();}

    不幸的是,这意味着您将无法再查询该集合.您需要访问各个文档.

  3. 定期运行 Cloud Functions 代码以删除过期文档.

另请参阅 Doug 描述此过程的优秀博客文章:如何使用 Cloud Tasks 安排 Cloud Functions 将来运行(构建 Firestore 文档 TTL).

Is there any TTL option on documents for Firebase Firestore . Where documents get auto deleted after that amount time

There is no such built-in functionality.

The easiest way to build it yourself is by:

  1. Adding a expirationTimestamp property to your documents.
  2. Denying read of documents whose expiration has passed in your security rules.

    match /collection/{document} {
      allow read: if resource.data.expirationTimestamp > request.time.date();
    }
    

    Unfortunately this means that you won't be able to query the collection anymore. You'll need to access the individual documents.

  3. Periodically run Cloud Functions code to delete expired documents.

Also see Doug's excellent blog post describing this process: How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL).

这篇关于Firebase Firestore 中的文档是否有任何 TTL(生存时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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