Firebase database rules No such method/property 'child'
<p>I'm new to firebase rules and am trying to write rules for the chat part of my web app. The chat part of my database has chatroom children which have 3 children each: user1, user2, and msgs. user1 has a value of one of the member's uid's, user2 has the value of the other member's uid, and msgs is an object made up of the message strings.</p>

<p>When a user starts a chat with another user, I want to make sure that the chatroom created follows the following criteria:</p>

<p>1) Either user1 or user2 value equals the user's uid.</p>

<p>2) Either user1 or user2 value equals the other member's uid.</p>

<p>3) The other member's uid is in the user's friends list.</p>

<p>Here is what I wrote in bolt:</p>

<pre><code>path /chats/{chat} is Chat{
    read() {isInChat(auth, chat)}               // Can only read if user's uid is equal to user1 or user2's value
    write() {createOnly(this)}                  // Can only append the chatroom to list of chatrooms
    validate() {(chat.child('user1').val() == auth.uid || chat.child('user2').val() == auth.uid) &amp;&amp; isFriend(auth, chat) }
}

function isInChat (auth, chatRoom) {            // Check if user1 or user2 is equal to user's uid
    return chatRoom.child('user1').val() == auth.uid || chatRoom.child('user2').val() == auth.uid;
}
function isFriend (auth, chat) {                // Check if other member of chat is in the user's friends list
    return root.child('users').child(auth.uid).child('friends').child(chat.child('user1').val()) != null || root.child('users').child(auth.uid).child('friends').child(chat.child('user2').val()) != null;
}
function createOnly (value) {                   // Make sure node being created does not already exist
    return prior(value) == null &amp;&amp; value != null;
}
type Chat {
  user1: String,
  user2: String,
  msgs: Object
}
</code></pre>

<p>This generates the following rules:</p>

<pre><code> "chats": {
      "$chat": {
        ".validate": "newData.hasChildren(['user1', 'user2', 'msgs']) 
                   &amp;&amp; ($chat.child('user1').val() == auth.uid 
                    || $chat.child('user2').val() == auth.uid) 
                   &amp;&amp; (newData.parent().parent().child('users').child(auth.uid).child('friends').child($chat.child('user1').val()) != null 
                    || newData.parent().parent().child('users').child(auth.uid).child('friends').child($chat.child('user2').val()) != null)",
        "user1": {
          ".validate": "newData.isString()"
        },
        "user2": {
          ".validate": "newData.isString()"
        },
        "msgs": {
          ".validate": "newData.hasChildren()"
        },
        "$other": {
          ".validate": "false"
        },
        ".read": "$chat.child('user1').val() == auth.uid
               || $chat.child('user2').val() == auth.uid",
        ".write": "data.val() == null &amp;&amp; newData.val() != null"
      }
    }
  }
</code></pre>

<p>However, when I try publish the rules I get the error <code>No such method/property 'child'</code> for the first <code>.validate</code> line and the <code>.read</code> line.</p>

<p>Can anyone please help me understand what is wrong with my rules and whether I'm approaching this correctly?</p>