Is there any TTL (Time To Live ) for Documents in Firebase Firestore
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).