Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a rule to prevent any deletion of node from database

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.existsbut 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.

like image 438
MrAlpha_SU Avatar asked Jan 29 '17 10:01

MrAlpha_SU


1 Answers

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 Cannot write null

like image 63
Frank van Puffelen Avatar answered Oct 24 '22 13:10

Frank van Puffelen