如何仅使Firebase实时数据库中节点中的某些字段不可编辑

时间:2019-04-25 14:05:11

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

我在firebase实时数据库中具有以下数据库结构。

Employee: 
{
  "+911234567890" : {
    "admin" : true,
    "companyId" : "C1",
    "depId" : "D5",
    "designation" : "D1",
    "dob" : "2019-04-02T18:30:00.000Z",
    "doj" : "2019-04-18T18:30:00.000Z",
    "empEmail" : "nishant.k@zetwerk.com",
    "empId" : "E4",
    "empPhone" : "+911234567890",
    "first_name" : "Nishanth",
    "gender" : "male",
    "last_name" : "K",
    "manager" : "M2",
    "type" : "permanent"
  }
}

我想使“ empPhone”和“ empEmail”字段不可编辑,而其余部分则可编辑。如何使用数据库规则来实现这一目标。 我试过了,但是没用,

{
"rules": {
    ".read": "auth != null",
      "employee": {
      ".indexOn": ["empPhone","empEmail", "empId", "companyId"],
      "$empPhone":{
        ".write":"auth != null && (!data.exists() || !newData.exists())"
      }
    }
}
}

0 个答案:

没有答案