Home > database >  Firebase conditions in where
Firebase conditions in where

Time:12-10

 QuerySnapshot querySnapshot = await FirebaseFirestore.instance
    .collection('stations')
    .where('norequest', isGreaterThan: 9)
    .get();

Here i want get if 'norequest' is a whole number like 10 , 20 , 30 , 40 something like this and greater than 5 ? How can i get that

CodePudding user response:

Future<List<YourModel>> getData() async {
  List<YourModel> yourModel = [];
  QuerySnapshot querySnapshot =
      await FirebaseFirestore.instance.collection('stations').where("norequest", isGreaterThan: 5).get();
  if (querySnapshot?.docs != null) {
    querySnapshot.docs.map((x) {
      if (int.parse(x.data()['norequest'].toString()) % 10 == 0) {
        yourModel.add(YourModel.fromJson(x.data()));
      }
    });
  }
  return yourModel;
}

CodePudding user response:

try this query:

QuerySnapshot querySnapshot = await FirebaseFirestore.instance
    .collection('stations')
    .where('norequest', isGreaterThan: 5)
    .where("norequest", whereIn: [10, 20, 30, 40])    
    .get();
  • Related