0

i am new Firebase. I want to delete data if they are older than 14 days. I am storing timestamp when create data. I have read below answer of Frank, but i can’t implement to my need. Need Help.

Delete firebase data older than 2 hours

enter image description here

Here is what i have done yet

let now = Date.now();
    let cutoff = now - 1587706383; //14 timestamp

    console.log(cutoff)

     firebase.database().ref('usuario',).on('value', dataSnapshot =>{
        dataSnapshot.forEach(user =>{
          user.child('eventos').forEach(evento =>{
            if (evento.val().timestamp === cutoff){
                evento.ref.remove()
            }
          })
        })
     });
Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
Mohamed Mamun
  • 211
  • 3
  • 15
  • Question: Do you want your *app* to delete data older than 14 days - in other words if you have 10 users, each users app would delete data or do you want an automated process that's independent of your app to perform that function? – Jay May 08 '20 at 15:39
  • I want a function that trigger every 1h to delete data they are older 14 days. I thought to implement Google cloud Functions with Schedule, but i can't use that kind functions in this project. That's why i was trying to do in the client-side. When ever the component mount, trigger this function! – Mohamed Mamun May 08 '20 at 16:16

0 Answers0