我对 Firestore 很陌生。我有这个查询显示聊天消息和新消息出现时的更新。我只希望当前用户(学校)看到来自他们自己学校的消息。如果我不包含 .where 子句 - 它会显示所有消息,但如果我使用它则不会显示任何内容(即使它们存在)
这是我的 firestore 页面图像的链接(因为我无法嵌入它):
我在挂载上调用方法:
mounted() {
//fetches the messages
this.fetchMessages(this.$route.params.id);
},
那么方法是:
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;
})
}
我在这里做错了什么吗?
慕少森
相关分类