防止“删除和更新”firebase 中的孩子

aaa*_*abc 4 security rules firebase firebase-security firebase-realtime-database

我看到没有办法将安全规则设置为阻止孩子的“删除和更新”。

".write": "!data.exists() && newData.exists() && !newData.exists()"
Run Code Online (Sandbox Code Playgroud)

那是没有道理的。

Jen*_*son 6

For future reference, the Firebase console lets you test database security rules, so you can find out what works right there before you publish those rules. That being said, if I'm understanding your question correctly, you want to allow users to add to the node, but not delete or update. You'd be looking for something along the lines of:

{
  "rules": {
    ...

    "childNodeName": {
       ".write": "!data.exists()"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

您不应该需要其他两个条件。更不用说,他们永远不会决定为真,因为这些条件无法满足。

如果您需要将多个子项添加到路径中,但您不希望用户在添加这些子项后对其进行修改,您也可以使用通配符:

{
  "rules": {
    ...

    "childNodeName": {
       "$pushId": {
          ".write": "!data.exists()"
      }
    }
  }
}  
Run Code Online (Sandbox Code Playgroud)