Firestore针对多个值查询文件

时间:2019-10-19 11:35:51

标签: flutter google-cloud-firestore

是否可以根据值数组查询文档字段,从而返回包含数组元素值之一的字段

                 _fireStore
                .collection('articles')
                .orderBy('created')
                .where('projectName', isEqualTo: listHearted)
                .getDocuments()
                .asStream(),

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我已经使用流中的流完成了它。

 Stream<List<DocumentSnapshot>> streamDoc;
  StreamController<List<DocumentSnapshot>> controller =
  StreamController<List<DocumentSnapshot>>();

 void docRef() {
Firestore _fireStore = Firestore.instance;

Stream<QuerySnapshot> snapshot = _fireStore
    .collection('articles')
    .orderBy('created')
    .getDocuments()
    .asStream();

List<DocumentSnapshot> listDoc = List<DocumentSnapshot>();
snapshot.listen((snapshot) {
  snapshot.documents.forEach((e) {
    if (SharedPrefList.listHearted
            .contains(e.data['projectName'].toString()) &&
        widget.type == 'hearted') {
      listDoc.add(e);
      controller.add(listDoc);
    }
    if (SharedPrefList.listSeen
            .contains(e.data['projectName'].toString()) &&
        widget.type == 'seen') {
      listDoc.add(e);
      controller.add(listDoc);
    }
  });
});

}