Modelling tournament brackets in MongoDB

那年仲夏 提交于 2020-06-26 07:18:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!