title: Trying to set up Cloud Firestore security rules using request.path
body: <p>I am struggling to get my head around some Firestore security concepts. I want to set up a rule based on the <code>request.path</code> property.</p>
  
  <p>My rule is this:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read, write: if request.path[0]=='appUsers';
      }
    }
  }
  </code></pre>
  
  <p>...and I then use <a href="https://github.com/angular/angularfire2" rel="nofollow noreferrer">AngularFire2</a> to add a document like this...</p>
  
  <pre><code>this.myAngularFirestore.doc('/appUsers/'+this.auth.auth.currentUser.uid).set({name: this.auth.auth.currentUser.displayName})
        .then(()=&gt;console.log('Added user'))
        .catch(err=&gt;console.log('Could not add user:', err.message));
  </code></pre>
  
  <p>I thought this should be simple <a href="https://firebase.google.com/docs/firestore/reference/security/?authuser=0#properties" rel="nofollow noreferrer">based on the docs</a> but all I ever get is the error - <code>Missing or insufficient permissions</code>.</p>
  
  <p>I know I am logged in correctly and I know the query works if I open up the security with <code>allow read,write: if true;</code> so what am I not getting here?
  Shouldn't <code>request.path[0]</code> evaluate to the string <code>appUsers</code> here and so allow the data to be written?</p>
  
  <p>Any ideas gratefully accepted as I'm not finding these rules much fun to out together so far.</p>
  
  <p>Cheers all</p>