I have a parent collection 'chats' on firestore with different ids which I am sending from the app. Each id also have a 'messages' collection.
The major thing I want to achieve is iterating through the documents of the parent (i.e 'chats') collection and checking if the document contains an id (e.g 31) then do something with the message collection of that document.
await FirebaseFirestore.instance.collection('chats').get().then((value){
print('value Size: ${value.size}'); //value.size here is returning 0
for (var element in value.docs) {
if (element.id.contains('31')) {
//Do something with the messages collection.
FirebaseFirestore.instance.collection('chats/${element.id}/messages').get().then((value){
for (var message in value.docs) {
// Do something with the message data
}
});
}
}
});
The value.size is returning 0. However, I don't have issues when I want to perform the same operation on the 'messages' collection.
Please, how can I acheive this??? Thank you in advance.