Vasanth Tulasi
Vasanth Tulasi

Reputation: 3

Prevent parent node deletion if there is not a single value in it

I am using Firebase to store data. When I delete all data within a single parent node, the parent node also gets deleted. A parent node exists only if there is at least a single value of data in it.

How do I modify the rules in such a way that the parent node always exists even if there is not a single value in it. (I set the values of .read and .write in the rules to true.)

enter image description here

In the above image, the parent 'Queue Members' has a value 'hello'. If I delete 'hello', the parent 'Queue Members' also gets deleted.

Upvotes: 0

Views: 204

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599631

There is no way to have a node without a value under it.

The Firebase Database automatically creates nodes as values are added under them. It also automatically deletes nodes when no value exists under them anymore.

This should typically not lead to any problems in your code, since requesting the value of a non-existing node leads to an empty snapshot. If you're having a problem with this in your code, it would be useful to see how you're trying to deal with it.

Upvotes: 1

Related Questions