I have an Flutter chat application.
The structure of FireStore is as below.
chats
(collection) > roomId
(random generated id, which is a document) > users
(collection) > email
(email of the user, which is a document) > messages
(collection) > messageId
(random generated id, which is a document) > the actual chat.
When I use the following code it works. This gives all the messages in a room by a particular user.
FirebaseFirestore.instance
.collection('chats')
.doc(roomId)
.collection('users')
.doc(user)
.collection('messages')
.orderBy('timestamp', descending: true)
.snapshots(),
However, I need to get a list of all the users in a room. This is the code that I tried and is not getting any result, empty list.
QuerySnapshot<Map<String, dynamic>> userCollection = await FirebaseFirestore.instance
.collection('chats')
.doc(roomId)
.collection('users')
.get();
Here is the rule that is set on the store.
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
I need to get the list of all the users in the room.
Any help is appreciated.