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

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

问题描述

Firebase Firestore的文档上是否有任何TTL选项.在该时间段后自动删除文档的地方

解决方案

没有此类内置功能.<​​/p>

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

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

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

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

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

另请参阅道格(Doug)出色的博客文章,其中描述了此过程: 解决方案

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天全站免登陆