Anusha Bhattacharya
Anusha Bhattacharya

Reputation: 43

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

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?

Upvotes: 2

Views: 1805

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598740

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);

Upvotes: 3

Related Questions