0

I am trying to fetch a good amount of data from firebase. When i normally load all data using single where clause it takes approximate 1 minute to load. i want to add multiple where clause so that i can check at the time of fetching so that i can optimize the time by not fetching unwanted data. How can i check multiple conditions while fetching the data from firebase realtimedatabase

Here is my code:

 var query = FirebaseDatabase.instance.reference().child(str_gender)
        .child('Facial Parts/Nose').orderByChild("noselength").equalTo(str_length);



Here i can check only by nose length but i want to filter it out by nose length,nosetype,nose width

in other language we can say

noselength=value and nosewidth=value and nosewidth=value

if condition satisfies then only i need to fetch data

so how to add multiple where clause in my existing code??

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
KUNAL HIRANI
  • 641
  • 1
  • 7
  • 20
  • Firebase Database queries can only order/filter on a single property. In many cases it is possible to combine the values you want to filter on into a single (synthetic) property. For an example of this and other approaches, see my answer here: http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase – Frank van Puffelen Jul 26 '20 at 15:03

1 Answers1

1

You cannot add multiple conditions in realtime database. One solution is to create an attribute that will contain all 3 fields:

length_width_type : 10_10_normal

And then do:

 var query = FirebaseDatabase.instance.reference().child(str_gender)
        .child('Facial Parts/Nose').orderByChild("length_width_type").equalTo(value);

Other solution is to use firestore since it supports multiple where clause:

void getData() async {
  var result = await Firestore.instance
      .collection("str_gender")
      .where("noseLength", isEqualTo: 10)
      .where("noseWidth", isEqualTo: 10)
      .getDocuments();
}
Peter Haddad
  • 78,874
  • 25
  • 140
  • 134