MrAlpha_SU
MrAlpha_SU

Reputation: 331

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.

Upvotes: 14

Views: 6195

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

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

Upvotes: 34

Related Questions