ios - 子集合的 Firestore 监听器
问题描述
我通过以下方式设置了 Firestore:
Channels [collection] ----> channelID ---> Messages [collection] ---> messageID
如何将 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)
}
}
这对我不起作用
解决方案
您不能让单个侦听器接收来自未知数量的子集合的更新。集合上的侦听器没有“通配符”运算符。您必须选择一个特定的集合或查询并为其附加一个侦听器。
推荐阅读
- r - 从 R 中的多个列中过滤前 50 个值
- azure-devops - 在 YAML 部署作业中部署后检查应用程序运行状况端点的最佳方法是什么?
- azure - 天蓝色 devops 工件和 npm 存储库问题
- git - 是否有用于“git status”的 Git Hook?
- video - 如何将 5FPS 视频转换为延时摄影?
- swift - 如何通过忽略时区将 UTC 字符串转换为日期?
- c# - 在事件处理程序中绑定 Button.text 属性
- scikit-learn - 具有 95% 置信区间的多类 AUC
- php - 为什么 Laravel vendor:publish 返回“无法找到可发布的资源”?
- c++ - 编译器是否有用 C++ 中的推断类型替换 auto 的功能?