我正在尝试从集合中查询一些文档,该查询应侦听查询的文档中所做的更改,因此我需要一个流。我正在关注(在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一直为假。我在这里错了吗?编辑:
match /requests/{requestId} {
allow read: if isLoggedIn();
allow write: if isLoggedIn();
}
删除每个where
和orderBy
时,也找不到任何东西。并且在请求集合中存在文档
当尝试仅从请求集合中以流形式查询1个文档时,他确实找到了结果
是因为我应该将索引添加到我的Firestore索引中?但这并不能解决我的第一个问题,即使没有where
和orderBy
,也不会获得任何数据
Firestore.instance.collection('collection')
.where('field', isEqualTo: 'value')
.orderBy('field')
.snapshots()
.listen((QuerySnapshot querySnapshot){
querySnapshot.documents.forEach((document) => print(document));
}
);