Search code examples
firebase-realtime-databasefirebase-security

firebase security-rules write access to only one specific field


is it possible to give update access to only one specific field ?

users
  + gaglajasdfer32fasfa
    - Name: Luke     // not allowed to update
    - likes: 3       // allowed to update

Solution

  • You will have to specify the rule for each field in that case as shown below:

    {
      "rules": {
        "users": {
          "$uid": {
            "Name": {
             ".write": "!data.exists()"
            }
          }
        }
      }
    }
    

    !data.exists() allows write operation only when it's absent now and hence allowing "Create" operations only and not "update" or "delete".

    Checkout the documentation to learn more about security rules.