How to retrieve data in an order from Firestore in reverse order?

Viewed 1106

I am making this Quiz android application where I will be storing the record of each user's individual highscore in Cloud FireStore. So I made this collection named users which only has 2 fields- username and highscore. I want to retrieve the username and highscore of the top ten players globally from there to display in the leaderboard. Please let me know how I can do it! Also will it be possible to get the current user's rank?

1 Answers

As shown in the documentation on ordering and limiting data, you can get the top 10 players with:

usersCollection.orderBy("highscore", Direction.DESCENDING).limit(10);
Related