0

是否可以针对值数组查询文档字段,其中将返回包含数组元素值之一的字段

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

2 回答 2

1

当前无法执行返回与某个字段中的多个值之一匹配的项目的查询。解决方法是对每个hearted 项目执行查询,并在客户端合并结果。

另见:

于 2019-10-19T13:58:59.407 回答
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);
    }
  });
});

}

于 2019-10-20T21:25:06.500 回答