Firebase FlatterFireStore,尝试通过一个请求从文档数组中获取集合数组

Firebase FlatterFireStore,尝试通过一个请求从文档数组中获取集合数组,firebase,flutter,google-cloud-firestore,collections,Firebase,Flutter,Google Cloud Firestore,Collections,我有一个我想访问的正在构建的应用程序,在FIRESTORE中,我有几个国家作为一个文档,在每个国家我有一个集合,在集合中我有一个我需要访问的所有文档的列表 例子: 我的代码: Stream getFavo({userId,countryName}){ 名单国家; 用于(countryName中的CountryModel c){ var ref=_db.collection('country').doc(c.countryName)。collection('chat')。where(“likes

我有一个我想访问的正在构建的应用程序,在FIRESTORE中,我有几个国家作为一个文档,在每个国家我有一个集合,在集合中我有一个我需要访问的所有文档的列表

例子:

我的代码:
Stream getFavo({userId,countryName}){
名单国家;
用于(countryName中的CountryModel c){
var ref=_db.collection('country').doc(c.countryName)。collection('chat')。where(“likes”,arrayContains:userId)。snapshots();
返回ref.map((snap)=>snap.docs.map((doc)=>RecentChat.fromJson(doc.data()).toList());
}
}

当前行为:只返回第一张单据


所需的行为:返回所有文档。

是的,实际上只返回第一个元素,因为您在循环的一侧执行
返回
,而不使用
关键字
收益

例子:
Stream getFavo({userId,countryName}){
名单国家;
用于(countryName中的CountryModel c){
var ref=_db.collection('country').doc(c.countryName)。collection('chat')。where(“likes”,arrayContains:userId)。snapshots();
生成ref.map((snap)=>snap.docs.map((doc)=>RecentChat.fromJson(doc.data()).toList());
}
}

你尝试过什么吗?Stream getFavo({userId,countryName}){List country;for(countryName中的CountryModel c){var ref=_db.collection('country').doc(c.countryName.).collection('chat')。where('likes',arrayContains:userId)。snapshots();return ref.map((snap)=>snap.docs.map((doc)=>RecentChat.fromJson(doc.data()).toList());}}但是,只返回第一个文档将该代码添加到您的问题中,无法读取。您忘记将其标记为
async*
仅返回第一个文档:(Stream getFavo({userId,countryName})async*{for(countryName中的CountryModel c){var ref=_db.collection('country').doc(c.countryName.).collection('chat').where('likes',arrayContains:userId.).snaps();yield*ref.map((snap)=>snap.doc)=>RecentChat.fromJson(doc.data()).toList());}
Stream<List<RecentChat>> getFavo({userId , countryName}) { 
    List<CountryModel> country;
    for(CountryModel c in countryName) {
        var ref = _db.collection('country').doc(c.countryName).collection('chat').where("likes", arrayContains: userId).snapshots(); 
        return ref.map((snap) => snap.docs.map((doc) => RecentChat.fromJson(doc.data())).toList());
    }
}
Stream<List<RecentChat>> getFavo({userId , countryName}) { 
    List<CountryModel> country;
    for(CountryModel c in countryName) {
        var ref = _db.collection('country').doc(c.countryName).collection('chat').where("likes", arrayContains: userId).snapshots(); 
        yield ref.map((snap) => snap.docs.map((doc) => RecentChat.fromJson(doc.data())).toList());
    }
}