I am trying to write rules to secure database. But I am confused on writing a rule which will prevent from deleting any node from database. I have read regarding newData.exists
but when I tried running it in simulator deletion was succeeded! As a node can be deleted by setting its value to null, so I tried simulating the value of node to null and it was successful, which was not desired.
Suppose I have this node:
root{
Number of Users:20
}
And I wrote these rules:
"Number of Users":{
".read":true,
".write":"auth!==null && newData.exists()"
}
Am I making any mistake, please correct me.
To allow adding new nodes, but prevent deleting or overwriting any node:
".write": "!data.exists()"
To allow adding and overwriting, but not deleting, any node:
".write": "newData.exists()"
Update: screenshot of the simulator for these rules
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With