Asaduzzaman Himel
Asaduzzaman Himel

Reputation: 107

How to expire a data after some specific time in firebase?

I am creating a School exam application where I give some questions to the database(firestore) and I want to expire those data from the database after some specific time!! how to do this in firebase

Upvotes: 0

Views: 798

Answers (1)

MarketerInCoderClothes
MarketerInCoderClothes

Reputation: 1236

Client-side centric:

  1. Record a "timestamp" upon creation of the exam.
  2. Make the client show the exam as "expired" if and when ("now" >= "timestamp + # of days or hours")

OR:

Server-side...

If you actually want to delete the data from the db or mark it as "expired", you can create a Firebase function.

Let's assume that when creating an exam/question, you're adding an "expiration_time" when that data is supposed to be marked as "expired" or be deleted altogether.

Have your Firebase function do the following:

  1. Query data where the "expiration_time" is less than or equal to "now".
  2. For each result, mark that data as "expired" or delete it altogether, depending on your use case.

After you test your function and you know it works, make it so that it's a "Scheduled Firebase function" (google it if you don't know, it's easy to set up) - for example, make it run every minute.

Upvotes: 2

Related Questions