0

I need to get document which lies between two dates that is sem_start_date and sem_end_date:

enter image description here

This is my code of getting values from firebase

getTestFeeStructure() async {
  feeTestModelList.clear();
  feeTestNameList.clear();
  FirebaseFirestore.instance
      .collection('feeStructureTest')
      .where('sem_start_date',isGreaterThanOrEqualTo:'21-05-2023')
      .where('sem_end_date',isLessThanOrEqualTo:'21-05-2023')
      .get()
      .then((QuerySnapshot querySnapshot) {
    for (var doc in querySnapshot.docs) {
      FeeTestModel feeModel = FeeTestModel(
        documentId: doc.id,
        feeName: doc["fee_name"],
        amount: doc["amount"],
        academicYear: doc["academic_year"],
        courseName: doc["course_name"],
        customFeeName: doc["custom_fee_name"],
        semId: doc["sem_id"],
        semStartDate:doc["sem_start_date"],
        semEndDate:doc["sem_end_date"],
      );
      feeTestModelList.add(feeModel);
      feeTestNameList.add(feeModel.feeName);
    }
    isLoading = false;
    update();
  });
}

I am getting error given below in image. Is there any way to get values

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Naveen
  • 63
  • 6

1 Answers1

0

The error message is quite clear: all relational conditions (>, <, etc) in a query in Firestore must be in the same field. There is no way in a Firestore query to perform such conditions across multiple fields.

From the Firestore documentation on its query limitations:

In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.

So you'll have to change this query to work around this limitation, most commonly by having one relational condition in the query and performing the rest of the filtering in your application code.

Also see:

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