1

Making a query to realtime firebase

DatabaseReference mReference = mDatabase.getReference("Cards/" + language + "/" + gameTitle); Query query = mReference.orderByChild("rank"); query.addValueEventListener

it suppose to sort it by rank and give as 1/2/3/4/5/6 values. Instead of that it returns 1/10/11/12/13/14/15/16/17/18/19/2/20/21 etc... Thats how hierarchy looks like (sorry for russian language but dont have english yet) enter image description here Looks like it sorting by first character instead of whole value

Bo Z
  • 2,359
  • 1
  • 13
  • 31

1 Answers1

1

it suppose to sort it by rank and give as 1/2/3/4/5/6 values. Instead of that it returns 1/10/11/12/13/14/15/16/17/18/19/2/20/21

That's the normal behaviour since you are ordering the results according to the rank property, which is of type String and not number. When you order strings, the elements are ordered lexicographically.

There are two ways in which you can solve this, either use my solution from the above answer or you change the type of your property to number. In my opinion, since all those value are numbers, is the solution you should go ahead with.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193