子集合的 Firestore 侦听器 [英] Firestore listener for sub collections
本文介绍了子集合的 Firestore 侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 Firestore 设置如下:
I have my Firestore setup in the following way:
频道[收藏] ----> 频道ID ---> 消息[收藏] --->消息ID
Channels [collection] ----> channelID ---> Messages [collection] ---> messageID
如何将 snapshotListener 添加到子集合消息"中?
How would I add snapshotListener to sub collection 'Messages' ?
Firestore.firestore().collection("Channels").document().collection("Messages").addSnapshotListener { (querySnapshot, error) in
guard let snapshot = querySnapshot else {
print("Error listening for channel updates: (error?.localizedDescription ?? "No error")")
return
}
snapshot.documentChanges.forEach { change in
print(change)
}
}
这对我不起作用
推荐答案
您不能让单个侦听器接收来自未知数量的子集合的更新.集合上的侦听器没有通配符"运算符.您必须选择一个特定的集合或查询,并为其附加一个侦听器.
You can't have a single listener receive updates from an unknown number of subcollection. There are no "wildcard" operators for listeners on collections. You have to choose a specific collection or query and attach a listener to that.
这篇关于子集合的 Firestore 侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文