title: Firebase firestore rules, read only when document contain specific value
body: <p>I was learning through official <a href="https://cloud.google.com/firestore/docs/security/secure-data#evaluating_documents_currently_in_the_database" rel="nofollow noreferrer">doc</a> for security rules, but i cant make it work.</p>
  
  <p>in my collections <code>users</code> under document <code>user</code> have some map values, one of them is <code>role: "guest"</code>. role values can be <code>"guest" or "superAdmin"</code></p>
  
  <p>i want access to <code>/users</code> only when <code>role == "superAdmin"</code></p>
  
  <p>here is what i tried</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /users/{userId} {
          allow read: if get(/databases/$(database)/documents/users/$(userId)).data.role == "superAdmin";
      }
    }
  }
  </code></pre>
  
  <p>and got error when i log in as <code>superAdmin</code></p>
  
  <blockquote>
    <p>ERROR Error: Missing or insufficient permissions.</p>
  </blockquote>
  
  <p>i believe i followed docs correctly. and found a similar question in <a href="https://stackoverflow.com/questions/46674372/firestore-security-rules-based-on-map-values">SO</a> where says some bug specific to evaluating nested fields in queries. But i have no nested queries. am i doing anything wrong here?</p>
  
  <p>here is my firestore look</p>
  
  <p><a href="https://i.stack.imgur.com/dEFRH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dEFRH.png" alt="enter image description here"></a></p>
  
  <p>Please help.</p>