【问题标题】:Firebase Rules not working properlyFirebase 规则无法正常工作
【发布时间】:2017-01-17 07:18:40
【问题描述】:

这是我在 firebase 中的数据结构,我在 Projects 标签下有多个项目,每个项目包含 staff 持有多个员工的密钥,每个员工再次包含 attendance 密钥和多个属性,如 OT1 ,@987654327 @ 等现在我希望 OT1 应该只保留数值。

在图片中查看我的数据结构

我已经尝试过这条规则

{
"rules": {
".read": true,
".write": true,
"Projects": {
  "$pid":{
  "staff":{
    "$sid":{
    "attendance":{
      "OT1":{".validate": "newData.isNumber()"}
    }
    }
  }
  }
},
"Empoyees": {
  "$staffid": {
    ".indexOn": "Type",
    "project": {
      ".indexOn": [
        "project2",
        "project1"
      ]
    }
  }
}
}
}

但它仍然允许我保存文本数据 它不限制我这个说法

attendanceRef.child("OT1").setValue("ABCDEFGH");

我应该改变什么规则。

【问题讨论】:

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


    【解决方案1】:

    哦,终于搞错了。

    规则应该是:

    {
    "rules": {
    ".read": true,
    ".write": true,
    "Projects": {
    "$pid":{
     "staff":{
       "$sid":{
         "attendance":{
          "$aid":{  // **this was the missing in my question**
            "OT1":{".validate": "newData.isNumber()"},
            "OT1_B":{".validate": "newData.isNumber()"},
            "OT2":{".validate": "newData.isNumber()"},
            "Total Mins":{".validate": "newData.isNumber()"}
       }
      }
     }
    }
    }
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      相关资源
      最近更新 更多