0

I am using the firebase for store some users data. So now i want to delete old data with check 'last_ubdated' time < 5 min. please help for create the firebase rule for this. below is my data structure. enter image description here

I have created the rule, but its not working properly.(code is below)

{ "rules": {
".read": true,
".write": true,
  "$drivers":{
    ".indexOn": ["driverId"],
      ".write": "newData.exists() || data.child('last_updated').val() > (now)",

  } } }
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Buddhika Lakshan
  • 182
  • 2
  • 13

2 Answers2

1

Firebase security rules can't change any data after it's been added. They only take effect at the time data is read or written by the client. If you want to arrange to delete something on a schedule, you will need another solution.

See also: Cloud Functions for Firebase trigger on time?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
1

As Doug said, security rules can't change the data. They merely affect what (read and write) operations are allowed.

An alternative would be to use a query to only request nodes that have not expired, and then use security rules to ensure only that query is allowed. For an example of that, see my answer here: How to make data unreadable once the time indicated on its time stamp has passed?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807