0

Is it possible to query documents fields against an array of values where it would return the fields which contain one of the array elements values

                 _fireStore
                .collection('articles')
                .orderBy('created')
                .where('projectName', isEqualTo: listHearted)
                .getDocuments()
                .asStream(),
Jofre
  • 3,718
  • 1
  • 23
  • 31
Shadi Ossaili
  • 545
  • 1
  • 4
  • 6
  • It's not clear what you're asking. Please edit the question to show examples of what documents you might expect to receive from a query. – Doug Stevenson Oct 19 '19 at 12:41

2 Answers2

1

There is currently no way to perform a query that returns items that match one of a number of values in a certain field. The workaround is to perform a query for each hearted project, and merge the results on the client.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
1

i've done it using a stream within a stream.

 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);
    }
  });
});

}

Shadi Ossaili
  • 545
  • 1
  • 4
  • 6