couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Larry <>
Subject Looking for help/ideas on how to fetch a Rank from a CouchDB based Highscores system
Date Wed, 26 Aug 2009 21:18:45 GMT
I currently have a a bunch of "high score" documents in couchdb. I'm trying
to find the best way for me to create a view that would allow me to easily
get the rank for a given score. As an example consider that I have 5 high

1) John, 100 pts
2) Jane, 90 pts
3) Bill, 85 pts
4) Jen, 70 pts
5) Bob, 55 pts

I have a function in my application called getRank( int $score) which would
return the rank (int) for the given score. So for example, using the scores

getRank(30) == 6
getRank(71) == 4
getRank(101) == 1

My document structure for a highscore is:

   "_id": "0a68cdbe4a8d130662217f3abf4046bc",
   "_rev": "1-1264504508",
   "score": "000000000000000000000000000000100",
   "player_name": "John"

My initial approach was to create a view that does emit([doc._id,doc.score],
null). I Then query the view by setting my start key to the *top* of the
view list and set my end key to the value of the score I'm looking for. I
then count the results that are returned and derive the rank that way. This
is grossly inefficient I know and I'm having a hard time trying to find the
most optimal way to construct this. Any thoughts are ideas would be greatly



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message