Home > Software design >  How to filter data base which contains map Firebase Flutter
How to filter data base which contains map Firebase Flutter

Time:07-21

Firebase DB

Hi everyone. I have a question. How I can filter my database via map inside FirebaseFirestore in Flutter. Let's say, If I want to filter my database using "spotProperties", I can do it by writing:

FirebaseFirestore.instance.collection('spots')
        .where('spotProperties', isGreaterThanOrEqualTo: 'gaps')
        .snapshots().listen((spots){
      mapRecords(spots);
    });

And it works fine.

How can I do it the same, if I would like to filter my database using "countryName" or "cityName"? I was trying to fix this using many ideas, but no results. For Your info - "cityName", "streetNumber" etc. are located inside map "spotAddress".

Thanks for feedback.

CodePudding user response:

You can use it like this.

   .where("spotAddress", isEqualTo: {
                          "countryName": "India",
                          "cityName": "delhi",
                          "streetNumber": 23
                        })

CodePudding user response:

It seems, that this works:

FirebaseFirestore.instance.collection('spots')
        .where('spotAddress.countryName', isGreaterThanOrEqualTo: 'U')
        .snapshots().listen((spots) {
      mapRecords(spots);

Main problem was, that when I added cityName or countryName to firestore i didn't trim white spaces. When I was trying to call data, there was a need to have one blank space on the beggining.

  • Related