-2

I have the JSON structure above enter image description here

I want to get the list of vehicles where their ids ends with "123"

I had tried to use Query.endAt() method but i'm not sure if i'm using it right or it shouldn't give the required output

Query vehiclesRef;
vehiclesRef = db.getReference("vehicles").orderByKey().endAt("\uf8ff123");

1 Answers1

3

Firebase Database queries can only perform prefix matches, so strings starting with a specific string or starting with a range of string. It is not possible to query for strings ending with a specific value, nor those ending with a range of values.

If you really want to do this within Firebase, consider also storing the reversed strings in the database:

"321_1_0"
"321_3_0"
"654_52_0"

Then you can query for strings starting with 321 with

vehiclesQuery = db.getReference("vehicles").orderByKey().startAt("321").endAt("321\uf8ff");
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807