在MongoDB中建模比赛括号 [英] Modelling tournament brackets in MongoDB

查看:88
本文介绍了在MongoDB中建模比赛括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将MongoDB移至该应用程序的某些部分。我认为像mongodb这样的基于文档的数据库非常适合锦标赛括号,但是我很难找到合适的模型。 (仍在尝试摆脱RDBMS教条的束缚)

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?

推荐答案

这两个锦标赛的变化基本上都取决于每场比赛,导致以下任一选项:

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.

这篇关于在MongoDB中建模比赛括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆