title: Firebase Security Rules for users to read and write their own data
body: <p>I'm working with Flutter and Firebase and came up with the following Firebase structure.</p>
  <p><img src="https://i.stack.imgur.com/D4PjC.png" alt="Room collections" /></p>
  <p>Room and user collections:</p>
  <p><img src="https://i.stack.imgur.com/stBCa.png" alt="2" /></p>
  <p>I want users to be able to read and write their data.
  And I wrote the following rules:</p>
  <p><img src="https://i.stack.imgur.com/0soiC.png" alt="rules" /></p>
  <p>For getting rooms, I've following code in Flutter:</p>
  <pre><code>     Stream&lt;List&lt;RoomModel&gt;&gt; getRooms() {
          var user = firebaseAuth.currentUser;
          return _db
              .collection('rooms')
              // .where(&quot;userId&quot;, &quot;==&quot;, user.uid)
              .snapshots()
              .map((snapshot) =&gt; snapshot.docs
                  .map((document) =&gt; RoomModel.fromFirestore(document.data()))
                  .toList());
        }
  </code></pre>
  <p>Room Model:</p>
  <pre><code>    // import 'package:firebase_auth/firebase_auth.dart';
      
      class RoomModel {
        final String roomId;
        final double price;
        final String location;
        final String userId;
      
        RoomModel(this.roomId, this.price, this.location, this.userId);
      
        Map&lt;String, dynamic&gt; toMap() {
          // final firebaseAuth = FirebaseAuth.instance;
          // var user = firebaseAuth.currentUser;
          return {
            'roomId': roomId,
            'price': price,
            'userId': userId,
            'location': location,
          };
        }
      
        RoomModel.fromFirestore(Map firestore)
            : roomId = firestore['roomId'],
              price = firestore['price'],
              location = firestore['location'],
              userId = firestore['userId'];
      }
  </code></pre>
  <p>But still, I'm getting all the rooms, including other user's room.</p>
  <p>And later I also wanted to read all the rooms. How should I do it?</p>