prevent “delete and update” a child in firebase

前端 未结 1 1488
一整个雨季
一整个雨季 2020-12-21 15:45

I see that there is no way to set security rules as preventing \"delete and update\" for a child.

\".write\": \"!data.exists() && newData.exists() &a         


        
相关标签:
1条回答
  • 2020-12-21 16:08

    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()"
          }
        }
      }
    }  
    
    0 讨论(0)
提交回复
热议问题