Firebase Firestore 中的文档是否有任何 TTL(生存时间)

Is there any TTL (Time To Live ) for Documents in Firebase Firestore

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

没有这样的内置功能。

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

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

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

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

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

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