title: Cloud Firestore Security Rules - (Read, Write)
body: <p>Within my Flutter App, I would like to allow a signed in user to be able to read the document/s that were created by them (Only If the DocumentID is same as UserID). The problem is that the documentID is generated by firebase automatically. when I explicitly specify the documentID using the signed in UserID, the user is not able to create more than one document because the documentID already exists. Please help...</p>
  <p>The result is always showing the snapshot error below...</p>
  <pre><code>StreamBuilder&lt;QuerySnapshot&gt;(
          stream: FirebaseFirestore.instance.collection('orders').snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return const Center(
                child: CircularProgressIndicator(),
              );
            } else {
              if (snapshot.hasError) {
                return const Center(
                  child: Text('Oops, something went wrong...'),
                );
              }
            }
  </code></pre>
  <p><strong>Adding Data to Firestore</strong></p>
  <pre><code>onPressed: () {
                    var firebaseUser = FirebaseAuth.instance.currentUser;
  
                    FirebaseFirestore.instance.collection('orders').add({
                      'date': FieldValue.serverTimestamp(),
                      'product': 'Jeans',
                      'total': cart.totalAmount,
                      'uid': firebaseUser!.uid,
                    });
                    cart.clearCart();
                  },
  </code></pre>
  <p><strong>Displaying data from Firestore</strong></p>
  <pre><code>StreamBuilder&lt;QuerySnapshot&gt;(
          stream: FirebaseFirestore.instance.collection('orders').snapshots(),
          builder: (context, snapshot) {
            if (snapshot.connectionState == ConnectionState.waiting) {
              return const Center(
                child: CircularProgressIndicator(),
              );
            } else {
              if (snapshot.hasError) {
                return const Center(
                  child: Text('Oops, something went wrong...'),
                );
              }
            }
  </code></pre>
  <p><strong>Security Rules</strong></p>
  <p><a href="https://i.stack.imgur.com/foOJs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/foOJs.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/DfYuO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DfYuO.png" alt="enter image description here" /></a></p>