As a newcomer to Firestore, I'm working on a query to display chat messages that update in real-time when new ones appear. However, I'm facing an issue where only messages from the current user's school should be visible. If I omit the .where clause, all messages are shown, but nothing appears when I include it (even though the messages exist)
You can view an image of my Firestore page through this link since embedding is not possible:
https://i.sstatic.net/pQU2F.jpg
I trigger the method on mount:
mounted() {
//fetches the messages
this.fetchMessages(this.$route.params.id);
},
The fetchMessages method used is as follows:
fetchMessages(schoolsIdentification) {
db.collection('chat')
.where("user.schoolId", "array-contains", schoolsIdentification)
.orderBy('date')
.onSnapshot((querySnapshot) => {
let allMessages = [];
querySnapshot.forEach(doc => {
allMessages.push(doc.data())
})
console.log("the all messages array length is:", allMessages.length)
this.messages = allMessages;
})
}
Is there something wrong with my implementation here?