0

I want to retrieve highest 10 scores from firebase . When i search stackoverflow i found some answers on here Firebase retrieve highest 100 score but i can not imagine how to implement them with REST API . My code is like this. I send request to end point and get response .

RestClient.Get<User>(databaseURL + getScoreText.text + ".json").Then(response =>
        {
            user = response;
            UpdateScore();
        });

Also for 2nd way, i can get all users' info by some json parser package and parse them and get the highest scores . But if my database gets bigger , i think i ll have problems . I need a way like "orderby". Do you know any way to implement "orderby" method to my restclient code ?

1 Answers1

0

Reading the firebase docs:

Filtered data is returned unordered: When using the REST API, the filtered results are returned in an undefined order since JSON interpreters don't enforce any ordering. If the order of your data is important you should sort the results in your application after they are returned from Firebase.

It seems like scaling is a real limitation of the realtime database. Firestore can do this pretty easily if you want to switch.

If you're sticking with realtime DB, I would save a separate database-reference that only ever contains the top 10 scores. So when a player gets a new score, they would only upload it to this reference if it's higher than the 10th top score. This would mean you would only have a DB reference containing 10 or less top scores, and scaling wouldn't be a problem. I'm not very familiar with realtime DB, but I'm sure you could write a security to rule to enforce this in a secure, server authoritative manner, at the very least a cloud function.

Charly
  • 450
  • 2
  • 13