I have a complex query to perform. I have added a composite index for this query in my Firebase project. This is the query.
FirebaseFirestore.instance
.collection('HouseDetails')
.where('housePrice', isGreaterThan: GV.price[0].ceil() - 1)
.where('housePrice', isLessThan: GV.price[1].ceil() + 1)
.where('houseArea', isGreaterThan: GV.area[0].ceil() - 1)
.where('houseArea', isLessThan: GV.area[1].ceil() + 1)
.where('bathrooms',
isEqualTo: int.parse(bathrooms.first).ceil() + 1)
.snapshots();
which throws an error
I/flutter ( 9116): ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
I/flutter ( 9116): The following assertion was thrown while handling a gesture:
I/flutter ( 9116): All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have
I/flutter ( 9116): inequality filters on 'FieldPath([housePrice])' and 'FieldPath([houseArea])'.
I/flutter ( 9116): 'package:cloud_firestore/src/query.dart':
I/flutter ( 9116): Failed assertion: line 484 pos 18: 'hasInequality == field'
After reading the documentation I understood that I cannot filter out multiple field types at once. But I did not understand how to perform the queries which needs more than one field for comparison (housePrice and houseArea in my case).
How Do I perform these queries?