DEV Community

Discussion on: Firestore, get collection with async/await

Collapse
 
jfar41 profile image
ricocode

I have some questions regarding async. i have code that looks like this:
queryRooms = async () => {
console.log('line 231');
let recentQuery = await this.chatRooms.where("uidArray", "in",
[this.user.uid+this.state.value.objectID,
this.state.value.objectID+this.user.uid]).get();
for (const qSnap of recentQuery.docs) {
console.log(qSnap.id);
let messagesRef = await this.chatRooms.doc(qSnap.id)

.collection('messages').get();
for (const messages of messagesRef.docs) {
console.log(messages.id, messages.data())
}
}
I call queryRooms in my react app everytime I change the value of the dropdownlist that has teachers students can chat with. However, my problem is that console.log('line 231') is being ran every time that I change the state but then I don't receive the requested information. After a random amount of presses I finally get a weird looking data structure from the queryRooms function. Is there a visible flaw with my async/await structure?