Trial Period mechanism - Flutter/Firebase
A better approach would be to store the free_trial_expiration
timestamp and derive whether the user is still in their free trial from that. That way you won't have to change any value when their free trial expires, you just have to check whether they are still in their free trial in your queries.
If you do want to set a field after a certain time period, you can do that with Cloud Functions. The two most common approaches are to either:
- Periodically check all potentially expired documents (e.g. all documents that have
"free_trial": true
, and update the ones that have expired, OR - Create a Cloud Task for each trial user (tasks are quite cheap), and set that task to trigger another Cloud Function when the trial period expires, so that you can update that specific document.
For more on these approaches, also see:
- Is there any TTL (Time To Live ) for Documents in Firebase Firestore
- How to create an auto delete mechanism for firestore? (deleting data after time period)
- Can a Firestore query listener "listen" to a cloud function?