title: Security rules : FirebaseError: Missing or insufficient permissions
body: <p>I'm attempting to allow each user read and write their own data using firestore, but I'm getting an insufficient permissions error. I'm not sure why.</p>
  <p>I have these rules in place for my firestore. I'm just trying to compare the user's UID (stored in createdBy property) with the user's uid accessible in request.auth.uid</p>
  <pre><code>rules_version = '2';
  service cloud.firestore {
    match /databases/{database}/documents {
       match /bots/{id} {
         allow read, write: if request.auth != null &amp;&amp; resource.data.createdBy == request.auth.uid;
                
         match /order_history/{id} {
           allow read, write: if request.auth != null &amp;&amp; resource.data.createdBy == request.auth.uid;
         }
      }
    }
  }
  </code></pre>
  <p>And my query that retrieves the data:</p>
  <pre><code>const orders = await getDocs(query(collectionGroup(db, 'order_history'), orderBy('datetime'), where('createdBy', '==', user.uid)));
      setOrders(orders.docs.map((doc) =&gt; ({
        ...doc.data()
      })))
  }
  </code></pre>
  <p>Here is an overview of my Firestore organization:
  <a href="https://i.stack.imgur.com/ZZOi5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZZOi5.jpg" alt="enter image description here" /></a></p>
  <p>My front returns <code>FirebaseError: Missing or insufficient permissions</code>.</p>
  <p>What did I do wrong?</p>