Firebase security rule: compare two objects for equality?

So, I want to write a security rule that forbids writing if the child of the node is different from the previous one. For instance. Imagine a situation where you want a node to register only on creation, but never was. Given this requirement, the most obvious solution would seem to be to verify that the new data is equal to the old data.

Unfortunately this does not work:

".write": "data.child('someNode').val() === newData.child('someNode').val()"

No more complicated approach when I try to pass an object to a string:

".write": "!data.exists() || (data.child('someNode').val() + '') === (newData.child('someNode').val() + '')"

Can this use case be supported in any case?

Important Note. The value in someNode must be an object and cannot be just a string or other primitive. In the case of primitives, any of these methods works fine.

+4
1

Firebase JSON. node .

.

".validate": "
  data.child('someNode/username').val() == newData.child('someNode/username').val()
  && data.child('someNode/displayName').val() == newData.child('someNode/displayName').val()"
"
+4

All Articles