子集合的Firestore侦听器 [英] Firestore listener for sub collections

查看:75
本文介绍了子集合的Firestore侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过以下方式设置了Firestore:

I have my Firestore setup in the following way:

频道[集合] ----> channelID --->消息[集合] ---> messageID

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆