Firebase Firestore中的文档是否有任何TTL(生存时间) [英] Is there any TTL (Time To Live ) for Documents in Firebase Firestore
问题描述
Firebase Firestore的文档上是否有任何TTL选项.在该时间段后自动删除文档的地方
没有此类内置功能.</p>
您自己构建它的最简单方法是:
- 在文档中添加
expirationTimestamp
属性. -
拒绝阅读在安全规则中已过期的文档.
match /collection/{document} { allow read: if resource.data.expirationTimestamp > request.time.date(); }
不幸的是,这意味着您将无法再查询集合.您需要访问各个文档.
-
定期运行Cloud Functions代码以删除过期的文档.
另请参阅道格(Doug)出色的博客文章,其中描述了此过程: 解决方案
There is no such built-in functionality.
The easiest way to build it yourself is by:
- Adding a
expirationTimestamp
property to your documents. 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.
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屋!