Reputation: 595
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(),
Upvotes: 0
Views: 834
Reputation: 595
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);
}
});
});
}
Upvotes: 1
Reputation: 598728
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:
Upvotes: 1