Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top