prevent “delete and update” a child in firebase

我与影子孤独终老i 提交于 2019-11-29 17:30:40

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()"
    }
  }
}

You shouldn't need those other two conditions. Not to mention, they will never resolve to true since those conditions cannot be met.

You can also use a wildcard if you need to add multiple children to a path but you don't want the user to modify those children once they've been added:

{
  "rules": {
    ...

    "childNodeName": {
       "$pushId": {
          ".write": "!data.exists()"
      }
    }
  }
}  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!