title: Firestore rules for document field
body: <p>I'm struggling within Firestore to set security rules for a document. With the RTDB is was possible to set rules for a specific object property and I'm trying to do the same with Firestore.</p>
  
  <p>RTDB Code:</p>
  
  <pre><code>"users": {
      ".read": true,
      ".indexOn": ["profile/name"],
      "$uid": {
          ".read": "auth != null",
          ".write":
              "$uid === auth.uid &amp;&amp; !data.exists()",
          "profile": {
              "birthday": {
                  ".write": "$uid === auth.uid"
              },
              "name": {
                  ".write": "$uid === auth.uid"
              },
              "banned": {
                  ".write": "root.child('admins').child(auth.uid).exists()"
              }
          }
      }
  }
  </code></pre>
  
  <p>Below the same code in Firestore:</p>
  
  <pre><code>service cloud.firestore {
      match /databases/{database}/documents {
          match /users/ {
              allow read
              match /{$user} {
                  allow read: if request.auth.uid != null
                  allow write: if request.auth.uid == request.resource.id &amp;&amp;  exists(/databases/$(database)/documents/users/$(request.resource.id)) === false
  
                  match /birthday {
                      allow write: if request.auth.uid == request.resource.id
                  }
                  match /name {
                      allow write: if request.auth.uid == request.resource.id
                  }
                  match /banned  {
                      allow write: get(/databases/$(database)/documents/users/$(request.auth.uid)).data.userType &gt; 3
                  }
  
              }
          }
      }
  }
  </code></pre>
  
  <p>When I'm writing security rules for a subcollection it's working fine. But for a document field it's not working. Is this not possible or is there a special <code>path</code> segment in the match reference? <a href="https://firebase.google.com/docs/firestore/reference/security/#path_segments" rel="noreferrer">The documentation</a> doesn't state anything about this.</p>