In Firestore API or Firebase Realtime Database API, multiple equalTo() cannot be used together as it is not supported.
However, there are several alternative solutions available to filter data in Flutter API using multiple equalTo():
Firestore.instance.collection('users')
.where('name', isEqualTo: 'John')
.where('age', isEqualTo: 25)
.getDocuments();
Firestore.instance.collection('users')
.where('name', isEqualTo: 'John')
.where('age', isEqualTo: 25)
.getDocuments();
Firestore.instance.collection('users')
.where('name', isEqualTo: 'John')
.where('age', isLessThanOrEqualTo: 30)
.where('city', isEqualTo: 'New York')
.getDocuments();
Firestore.instance.collection('users')
.snapshots()
.map((snapshot) => snapshot.documents.where((document) {
final name = document['name'] as String;
final age = document['age'] as int;
final city = document['city'] as String;
return name == 'John' && age <= 30 && city == 'New York';
}))
.listen((data) => print(data));
All of these solutions have their own advantages and trade-offs, and the optimal approach depends on the specific use case.
Asked: 2023-05-16 20:46:49 +0000
Seen: 10 times
Last updated: May 16 '23