问题
I've been experimenting with MongoDB in order to move some parts of an app to it. I'm thinking a document-based db like mongodb would be a nice fit for tournament brackets but I'm having sort of a hard time coming up with a suitable model. (still trying to break free from RDBMS dogma)
Anyone have any ideas for a good way to model Single AND Double-elimination tournament brackets?
回答1:
Both tournament variation basically come down to each match either resulting in one of these options :
- Player wins and advances to next round
- Player wins and wins the tournament
- Player loses and exits the tournament
- Player loses and advances to loser bracket
So, if you model it so that you have a collection of matches with a schema like :
{
_id :.., <- match id
players:[playerId1, playerId2],
resultForWinner: <either "WINS_TOURNAMENT" or match id of next match>
resultForLoser: <either "EXIT_TOURNAMENT" or match id of loser bracket match
}
You can compose both types of tournament brackets with this schema and reuse your tournament logic without making a distinction between the two other than bracket setup.
来源:https://stackoverflow.com/questions/2181652/modelling-tournament-brackets-in-mongodb