【问题标题】:Is there any TTL (Time To Live ) for Documents in Firebase FirestoreFirebase Firestore 中的文档是否有任何 TTL(生存时间)
【发布时间】:2018-04-20 18:39:24
【问题描述】:

Firebase Firestore 的文档是否有任何 TTL 选项。在这段时间之后,文档在哪里被自动删除

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    没有这样的内置功能。

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

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

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

      很遗憾,这意味着您将无法再查询该集合。您需要访问各个文档。

    3. Periodically run Cloud Functions code 删除过期文档。

    另请参阅 Doug 描述此过程的出色博客文章:How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL)

    【讨论】:

    • 此外,您现在可以使用 Cloud Tasks 来安排执行未来删除文档的功能。
    • Cloud Tasks 需要付费才能使用吗?
    • cloud.google.com/tasks#pricing "每月前 100 万次操作是免费的"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    相关资源
    最近更新 更多