async def boards(ctx, map_code, level, title, query): """Display boards for scoreboard and leaderboard commands.""" rank_number = 1 async for entry in WorldRecords.find(query).sort("record", 1).limit(10): # Do stuff for first record entry . . rank_number += 1
I have this code to display the top 10 time records of a race.
How can I change the rank # to be a part of the document, rather than an iteration count in a loop?
I would like to add a field for rank and have that automatically update the others for that particular race.
If there were 3 records:
and a new one comes in say 5.12,
it would insert it between 6.35 and 3.23 giving it rank 2 and moving the others below it to 3 and 4, and so on.
Would triggers be a good solution to this? or would there be some way to do it in Python?