Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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():

  1. Using a combination of where() and isEqualTo() methods, we can achieve multiple equalTo() filters. For example:
Firestore.instance.collection('users')
  .where('name', isEqualTo: 'John')
  .where('age', isEqualTo: 25)
  .getDocuments();
  1. Using a compound query that combines multiple queries with the same operator. For example:
Firestore.instance.collection('users')
  .where('name', isEqualTo: 'John')
  .where('age', isEqualTo: 25)
  .getDocuments();
  1. Using a single where() method and chaining multiple conditions with logical operators. For example:
Firestore.instance.collection('users')
  .where('name', isEqualTo: 'John')
  .where('age', isLessThanOrEqualTo: 30)
  .where('city', isEqualTo: 'New York')
  .getDocuments();
  1. Using a custom function to filter the data. This approach can be useful when you need to perform complex filtering that cannot be achieved with built-in methods. For example:
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.