-1

I am using Firebase realtime database in Android app, and have data like this:

Database image

I want to delete the "point": tab of all users at the weekend. Auto delete every weekend. how can I do that.

  • Do you want to do it as an Admin or do you want it to autodelete for each user when they open the app? – Berenluth May 15 '19 at 13:33
  • I want to do as an administrator – Efendiyev Efendi May 15 '19 at 13:36
  • Please check the duplicate. You can use for that [Cloud Scheduler](https://cloud.google.com/scheduler/). – Alex Mamo May 15 '19 at 13:40
  • About what preceisely? – Efendiyev Efendi May 15 '19 at 13:59
  • To run a Cloud Function on a schedule, see https://stackoverflow.com/questions/42790735/cloud-functions-for-firebase-trigger-on-time (@AlexMamo: you might want to update your answer to also indicate the new feature in Firebase, or close it as a dupe against this one). To then clean up data from the realtime database, see https://stackoverflow.com/questions/32004582/delete-firebase-data-older-than-2-hours, which includes a link to the same code in the `function-samples` repo. – Frank van Puffelen May 15 '19 at 14:10
  • @EfendiyevEfendi Please check again the duplicate answer. Is updated with new infos. Thanks! – Alex Mamo May 15 '19 at 14:56
  • still could not solve the problem. I can't delete point in all users in bulk – Efendiyev Efendi May 15 '19 at 16:16

1 Answers1

0

I suggest you to write a script that loop through the users and for each user remove the "point" entry, firebase provide a basic function to do it

userRef.child("point").remove();

You can write it in the language you prefer (I had a similar problem and i wrote it in python using a library).

Once the script is done, you just have to schedule it somewhere. If you have your own server you can use crontab (in linux) and schedule it to run every weekend. For example this run your script every Sunday at 5pm.

0 17 * * sun  /scripts/deleteFirebasePoints.sh

If you don't have your own server you can use some services like AWS or Google Cloud. It's also possible to use Firebase Cloud Functions to do it, it allows you to create your own function easily, but last time I used it it was a bit complicated to schedule it.

Berenluth
  • 509
  • 3
  • 13
  • Can you give me more information? – Efendiyev Efendi May 15 '19 at 13:49
  • About what preceisely? – Berenluth May 15 '19 at 13:50
  • You said you could do it with Firebase Cloud Functions. can i do with it? – Efendiyev Efendi May 15 '19 at 13:54
  • or how can I do with Google Cloud – Efendiyev Efendi May 15 '19 at 13:57
  • So, you can really easily place your function on firebase function, the only problem is schedule it to run automatically, here you can find some info about the official way to do it https://firebase.googleblog.com/2019/04/schedule-cloud-functions-firebase-cron.html The cost is just 10cents per month (per job scheduled) and it's reliable and stable – Berenluth May 15 '19 at 13:57
  • Keep in mind that firebase functions can be triggered by calling the url, so i suggest you to check the time in your code to be sure that it's a real call, instead of deleting the points in a random day of the week just because you called the function – Berenluth May 15 '19 at 14:02
  • I just found this open source project that allows you to create something like cronjob, but online https://cron-job.org/en/ – Berenluth May 15 '19 at 14:03
  • still could not solve the problem. I can't delete point in all users in bulk – Efendiyev Efendi May 15 '19 at 16:16
  • Why not? Just put the pieces together, write a function to delete points, put it in firebase functions, AWS, google cloud or wherever you want, and schedule it with one of the two options that i gave you There's no other way to do it automatically in Firebase – Berenluth May 15 '19 at 16:24