0

I am using Firebase for data storage. Inside I have the following collection:

enter image description here

I would like to make a request that would bring up all posts where 'qtquartos'> 4 and 'vagasgaragem'> 3. I researched a lot, read the documentation but found nothing about and how to make this kind of request.

This is the test query I was trying to perform with 2 specs, however I was unsuccessful.

/posts.json?orderBy="qtquartos"&startAt="5"&"vagasgaragem=startAt=3"
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
leandror
  • 59
  • 9
  • 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. But that only works for one range filter, the others would need to be equality filters, which in your example isn't the case. So the only remaining option is to perform one filter on the server, and do the other on the client. – Frank van Puffelen Dec 04 '19 at 00:53
  • Well... unless you find a way to combine the values of `qtquartos` and `vagasgaragem` into a single value, which is range filterable. It is incredibly rare to find a way to do so, but geohashes are an example of doing so. Which is why there is a GeoFire library on Firebase that allows you to filter on a range of latitude and longitude. But as said, this is really rare, and I doubt you can easily combine your `qtquartos` and `vagasgaragem` into a single value. – Frank van Puffelen Dec 04 '19 at 00:56

1 Answers1

1

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: Query based on multiple where clauses in Firebase.

But that only works for one range filter, the others would need to be equality filters, which in your example isn't the case. So the only remaining option is to perform one filter on the server, and do the other on the client.

The only other option is to find a way to combine the values of qtquartos and vagasgaragem into a single value, which is range filterable. It is incredibly rare to find a way to do so, but geohashes are an example of doing so. Which is why there is a GeoFire library on Firebase that allows you to filter on a range of latitude and longitude. But as said, this is really rare, and I doubt you can easily combine your qtquartos and vagasgaragem into a single value.

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