1

I am developing an android app using firebase. I have a user database like this-

user:{
      uid:{
           uname:user1,
           email:[email protected],
           phone:1234567890,
           level:20,
           score:50
          } 
      }

I set "score" node to false for both read and write. And I set both read and write rules for other nodes to true. Both goes fine. But there are many child nodes under each user node. So I have to write read and write rule for each child node. Except "score" node , other nodes have the same rule. Is there some ways to set same rule for multiple child node without writing rules for each node.

1
  • To make this easier, I suggest reorganizing your data in two different top-level nodes, and give each top-level node access according to the permission that each child should have that is common to each child. In other words, organize your children based on permission, not all bundled together. Commented Nov 13, 2019 at 18:28

1 Answer 1

1

You can use a $ variable to match all nodes that haven't been matches explicitly. So for your use-case that'd be something like:

{
  "rules": {
    "users": {
      "$uid": {
        "score": {
          // these rules apply to score
        },
        "$others": {
          // these rules apply to all other child nodes/properties
        }
      }
    }
  }
}