title: How do I access the document ID in firestore rules
body: <p>I am seemingly unable to access the resource.id value when trying queries using these rules. when I manually enter the schools id (the commented out line) the data returns fine. I only have 1 school and the doc ID definitely matches the string. but when I ask to match to the resource.id value, my rules return an 'insufficient permissions' error.</p>
  <pre><code>    rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
              //functions
          function signedIn() {
          return request.auth.uid != null;
              }
          
          function returnUID(){
          return request.auth.uid;
          }
    
    function getUserData() {
      return get(/databases/$(database)/documents/All%20Users/$(request.auth.uid)).data;
  }
    
    
                  match /All%20Users/{userID} {
            allow read,write: if 
            signedIn() &amp;&amp; returnUID() == userID;
            }
    
            match /All%20Schools/{schoolID}{
              allow read, write: if
           //  signedIn() &amp;&amp; getUserData().school == &quot;f7asMxUvTs3uFhE08AJr&quot;
               signedIn() &amp;&amp; getUserData().school == resource.id
            }
            
            
      
    }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/viVVG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/viVVG.png" alt="Image of Data Hierarchy" /></a></p>
  <p>my structure is like this</p>
  <p>All Schools / school (document) / Classrooms (subcollection)
  All Users / User (document) (each user doc has a classroomID associated to it)</p>
  <p>as a point of reference this is a query that is successful</p>
  <p><code> var docRef = db.collection(&quot;All Users&quot;).doc(uid).get()</code></p>
  <p>and the one that is failing</p>
  <p><code>db.collection(&quot;All Schools/&quot; + properties.schoolid + &quot;/Classrooms&quot;).onSnapshot()</code></p>
  <p>[update]
  the working set of rules!</p>
  <pre><code>rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
              //functions
          function signedIn() {
          return request.auth.uid != null;
              }
          
          function returnUID(){
          return request.auth.uid;
          }
    
    function getUserData() {
      return get(/databases/$(database)/documents/All%20Users/$(request.auth.uid)).data;
  }
    
    
                  match /All%20Users/{userID} {
            allow read,write: if 
            signedIn() &amp;&amp; returnUID() == userID;
            }
    
            match /All%20Schools/{schoolID}{
              allow read, write: if   schoolID == 'f7asMxUvTs3uFhE08AJr'
             
            }
            match /All%20Schools/{schoolID}/Classrooms/{classId} {
    allow read, write: if getUserData().school == schoolID;
  }
            match /All%20Schools/{schoolID}/Student%20List/{student} {
    allow read, write: if getUserData().school == schoolID;
  }
      match /All%20Schools/{schoolID}/Staff/{staff} {
    allow read, write: if getUserData().school == schoolID;
  }
    }
  }
  </code></pre>