0

Added a query mentioned below and also created the index in firebase but I don't know what happened since yesterday it is not showing data as per this query and if I remove this:- .where('age', isLessThanOrEqualTo:currentUser.ageRange['max']) from the below query then it shows the data other wise no data. Earlier this was working fine with no problem.

I have tried flutter clean but still no success, pls help me out as I want to implement this in project.

query() {
    if (currentUser.showGender == 'everyone') {
      return docRef
          .where('age', isGreaterThanOrEqualTo: currentUser.ageRange['min'])
          .where('age', isLessThanOrEqualTo:currentUser.ageRange['max'])
          .orderBy('age', descending: false).limit(docLimit);
    } else {
      return docRef
          .where('editInfo.userGender', isEqualTo: currentUser.showGender)
          .where('age', isGreaterThanOrEqualTo:currentUser.ageRange['min'])
          .where('age', isLessThanOrEqualTo: currentUser.ageRange['max'])
          .orderBy('age', descending: false).limit(docLimit);
    }
  }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
GAGAN SINGH
  • 261
  • 2
  • 17
  • If you need a composite index, check your debug console and follow the link in That error message, and create an index. – Huthaifa Muayyad Aug 05 '21 at 17:06
  • the index has been created and there is no such error appears... – GAGAN SINGH Aug 05 '21 at 17:30
  • Hi, I found a related case that maybe could be helpful for you about the [In queries](https://stackoverflow.com/questions/61362991/compund-query-with-or-operator-flutter-and-firebase), that could be a solution for your issue seems pretty similar for me. – Vicky Aug 06 '21 at 10:59

1 Answers1

0

I believe the issue might be because of you're trying to run two range queries separately.

You may won't be able to do that as it's one of the limitation of querying.

You can try including both the comparisons in the single query like .where("age",isGreater... : x, isLess..: y)

You can read about how querying works in firebase here: https://firebase.google.com/docs/firestore/query-data/queries

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rutvik_110
  • 66
  • 1
  • 4
  • Thanks for this...Yes, I have also tried doing this but still not able to get data and if I remove .where('age', isLessThanOrEqualTo:currentUser.ageRange['max']) then it works fine. And I don't know how it was working fine earlier as I haven't made any changes on this page then what wrong went here..... – GAGAN SINGH Aug 06 '21 at 06:12