Firebase Firestore 中的文档是否有任何 TTL(生存时间) [英] Is there any TTL (Time To Live ) for Documents in Firebase Firestore
问题描述
Firebase Firestore 的文档是否有任何 TTL 选项.在那段时间之后文档被自动删除
没有这样的内置功能.</p>
自己构建它的最简单方法是:
- 向您的文档添加
expirationTimestamp
属性. 拒绝读取在您的安全规则中已过期的文档.
match/collection/{document} {允许读取:如果 resource.data.expirationTimestamp >request.time.date();}
不幸的是,这意味着您将无法再查询该集合.您需要访问各个文档.
定期运行 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:
- 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屋!