【问题标题】:How set same rule for multiple child nodes如何为多个子节点设置相同的规则
【发布时间】:2019-11-13 18:23:31
【问题描述】:

我正在使用 firebase 开发一个 android 应用程序。我有一个这样的用户数据库-

user:{
      uid:{
           uname:user1,
           email:user1@gmail.com,
           phone:1234567890,
           level:20,
           score:50
          } 
      }

我将“分数”节点设置为 false 进行读写。我将其他节点的读写规则都设置为 true。两者都很好。 但是每个用户节点下有很多子节点。所以我必须为每个子节点编写读写规则。除了“score”节点,其他节点规则相同。是否有一些方法可以为多个子节点设置相同的规则,而无需为每个节点编写规则。

【问题讨论】:

  • 为了方便起见,我建议在两个不同的顶级节点中重新组织您的数据,并根据每个孩子应该拥有的每个孩子共有的权限授予每个顶级节点访问权限。换句话说,根据许可组织您的孩子,而不是全部捆绑在一起。

标签: firebase firebase-realtime-database firebase-security


【解决方案1】:

您可以使用$ 变量来匹配所有未明确匹配的节点。因此,对于您的用例来说,就像这样:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2018-05-08
    • 1970-01-01
    相关资源
    最近更新 更多