Check out the leaderboard example for a way to do this: https://www.firebase.com/tutorial/#example/leaderboard
The basic principle is that in addition to setting the name and score in a user object, you can use setWithPriority
to also set a priority for it. Priority in this particular case can be the user's score (if its numeric, it will automatically be sorted for you). You can then use the .limit(10)
query to get a list of top 10 users.
You'll also have to implement the child_added
, child_changed
and child_removed
events to handle the cases of a new user entering the top 10, someone changing position and someone leaving the top 10 list respectively.