Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there any TTL option on documents for Firebase Firestore . Where documents get auto deleted after that amount time

like image 462
Mahi Tej Gvp Avatar asked Nov 08 '17 07:11

Mahi Tej Gvp


People also ask

Is Firebase firestore real time?

Firebase offers two cloud-based, client-accessible database solutions that support realtime data syncing: Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model.

What are the Realtime Database limits in Firebase?

256 MB from the REST API; 16 MB from the SDKs. The total data in each write operation should be less than 256 MB. Multi-path updates are subject to the same size limitation.

How many documents can firestore handle?

10 for single-document requests and query requests. 20 for multi-document reads, transactions, and batched writes. The previous limit of 10 also applies to each operation.

Is firestore eventually consistent?

Firestore in Datastore mode Eventual consistency: Datastore queries become strongly consistent unless you explicitly request eventual consistency. Queries in transactions are no longer required to be ancestor queries. Transactions are no longer limited to 25 entity groups.


1 Answers

There is no such built-in functionality.

The easiest way to build it yourself is by:

  1. Adding a expirationTimestamp property to your documents.
  2. 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.

  3. 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).

like image 84
Frank van Puffelen Avatar answered Oct 21 '22 16:10

Frank van Puffelen