Firestore收集查询作为扑打中的流

问题描述 投票:0回答:1

我正在尝试从集合中查询一些文档,该查询应侦听查询的文档中所做的更改,因此我需要一个流。我正在关注(在Dart / Flutter中)

  Stream<List<MatchRequest>> _getNewMatches() {
    return Collection<MatchRequest>(path: 'requests')
        .ref
        .where('status', isNull: true)
        .where('users', arrayContains: ['$currentUid'])
        .orderBy('last_activity')
        .snapshots()
        .map((list) => list.documents.map(
            (doc) => Global.models[MatchRequest](doc.data) as MatchRequest));
  }
<< [

然后,我使用StreamBuilder,其中stream调用上述方法,然后builder检查snapshot.hasData。但是它一直在加载,snapshot.hasData一直为假。我在这里错了吗?编辑:

    我的firestore安全规则包含:
  1. match /requests/{requestId} { allow read: if isLoggedIn(); allow write: if isLoggedIn(); }

    删除每个whereorderBy时,也找不到任何东西。并且在请求集合中存在文档
  2. 当尝试仅从请求集合中以流形式查询1个文档时,他确实找到了结果

  3. 是因为我应该将索引添加到我的Firestore索引中?但这并不能解决我的第一个问题,即使没有whereorderBy,也不会获得任何数据

  4. 我正在尝试从集合中查询一些文档,该查询应侦听查询的文档中所做的更改,因此我需要一个流。我正在关注(在Dart / Flutter中)Stream

firebase flutter google-cloud-firestore stream
1个回答
1
投票
Firestore.instance.collection('collection') .where('field', isEqualTo: 'value') .orderBy('field') .snapshots() .listen((QuerySnapshot querySnapshot){ querySnapshot.documents.forEach((document) => print(document)); } );
© www.soinside.com 2019 - 2024. All rights reserved.