title: Firebase security write rule of child based on user existence
body: <p>Here is my security structure so far:</p>
  
  <pre><code>{
      "rules":
      {
          "users":
          {
              "$user":
              {
                  ".read": true,
                  "Age":
                  {
                      ".write": "$user === auth.uid",
                      ".validate": "newData.isNumber()"
                  },
                  "Name":
                  {
                      ".write": "$user === auth.uid",
                      ".validate": "newData.isString()"
                  },
                  "friends":
                  {
                      "$friend":
                      {
                          "Age":
                          {
                              ".write": "$user === auth.uid || $friend === auth.uid",
                              ".validate": "newData.isString()"
                          },
                          "Name":
                          {
                              ".write": "$user === auth.uid || $friend === auth.uid",
                              ".validate": "newData.isNumber()"
                          }
                      } 
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>Now, when I am trying to write to '$user' to Users, I have following error:</p>
  
  <pre><code>Attempt to write Success({"42":{"Age":42,"Name":"Nick","friends":{"11":{"Age":11,"Name":"Rob"}}}}) to /users with auth=Success({"id":42,"provider":"anonymous","uid":"anonymous:42"})
  /
  /users
  
  No .write rule allowed the operation.
  Write was denied.
  </code></pre>
  
  <p>When I set <code>.write</code> rule to users, then all write rules will be overwritten. I need to specify that all characteristics of <code>$user</code> can be written by <code>$user</code> only, but <code>$friend</code> can be written by <code>$friend</code> and <code>$user</code>. When I push users, I push them with friends, but then I will need the Friends to be able to change the their data at different users paths. Do you have any ideas?</p>