我的 Firestore 设置如下:
Channels [collection] ----> channelID ---> Messages [collection] ---> 消息ID
如何将 snapshotListener 添加到子集合“消息”?
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)
}
}
这对我不起作用
最佳答案
您不能让单个监听器从未知数量的子集合中接收更新。集合中的监听器没有“通配符”运算符。您必须选择一个特定的集合或查询并为其附加一个监听器。
关于ios - 子集合的 Firestore 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53227376/