0

I am using Firebase for Unity to retrieve top 100 scores using:

FirebaseDatabase.DefaultInstance.GetReference("users").OrderByChild("stat/score").LimitToFirst(100).GetValueAsync()

Everything is fine, however, if a user is not in the TOP 100, I still want to show the user rank, like if the user is ranked in the "1004" place, I want to retrieve that value for a specific user and view it.

I do not want to retrieve the whole user's data and retrieve user ranking on the client side since users data will increase to a large amount.

My firebase database structure is as following:

users
    userID
        stat
           score
Dror
  • 1,262
  • 3
  • 21
  • 34
  • 1
    Firebase doesn't track the index of child nodes. So the only way to know that a node is number 104, is by sorting/reading the 103 nodes before it. For some more on this, see Dan's excellent answer here: https://stackoverflow.com/questions/46720997/leaderboard-ranking-with-firebase. While that is about Cloud Firestore, the same applies to the Realtime Database. Also see my answers here: https://stackoverflow.com/q/52961118, here https://stackoverflow.com/q/55318674 and here https://stackoverflow.com/q/48128031 – Frank van Puffelen May 30 '19 at 13:31
  • Thanks for the reply. Pity there is no straightforward solution. – Dror May 30 '19 at 18:17

0 Answers0