数据结构 - 如何在MongoDB/NoSQL中设计篮球联赛的数据模型?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-04-25 09:04:40
0
1
577

本人是mongoDB新手,看过了官网上关于嵌入式非规范化数据库的介绍,但是面对实例的时候仍然是一头雾水.(官网上面的实例只有两三个collection,感觉比实际应用简单太多)
每年一个赛季,一个联赛对应多只队伍,每个队伍有多名队员.队员属性有身高体重所属球队球衣号码场上位置(队员有可能转会,但某一特定时间只属于一个球队).联赛有常规赛,季后赛之分,每场比赛有主/客队,需要记录下每个上场队员的得分/篮板/助攻/盖帽/抢断以及每一个事件的时间戳.每场比赛对应多个新闻报道文章
典型应用场景:
最新10场比赛的主/客队得分,胜负
所有球队的积分排名
所有球队在本赛季的平均得分/篮板/助攻/盖帽/抢断 前10名排行榜
所有球员在本赛季的平均得分/篮板/助攻/盖帽/抢断 前10名排行榜
某场比赛中主客队球队本场比赛的得分篮板助攻命中率等
某场比赛中主客队球员在本场比赛的得分篮板助攻命中率等
所有球员在某个赛季中的各项数据排行
某个球员在各个赛季中的平均各项数据(转会过的球员有可能在不同球队)

可否给出一完整的数据模型结构设计,万分感谢!
一些想不明白的问题:
是否应该把球员嵌入到球队中?如何处理转会问题?
是否应该把每场比赛的数据嵌入到每场比赛中?如果是,又如何关联球员与每一次得分/..事件的关系?
在哪里非规范化数据,感觉不管怎么设计,在汇总球队,或者球员的历史数据的时候,和做排名的时候,都要扫描整个数据库,这不科学吧...
在哪里做索引可以显著的提高性能?

这个应用场景到底合适不合适用nosql.................

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all (1)
Ty80

The big principle is to design based on Access Pattern. Fortunately, we already have typical application scenarios.

  1. The one-to-many relationship between team and player can be embedded or separated. It mainly depends on whether these two data are often used together. Examples of using them together: SegmentFault's questions and answers are also one-to-many, but are often displayed together. If not, you can separate it and add the player's name, _id, playing time and other basic information to the team. This kind of denormalization will require one more place to update when it needs to be updated. But since the update frequency of this information (such as transfers) is very low and it is read a lot, it is still worth it.

  2. Statistics. If you recalculate a player's historical data, no matter what data inventory is used, you need to traverse the entire database, right? This is another trade-off before reading and writing. Obviously, data updates are much less than queries, so caching statistical data is meaningful. Furthermore, some statistics are constant, such as those for a team in a given season. When updating, it can be updated in real time, or some intermediate results can be cached, such as the average value from the total number and times to help calculations. Alternatively, updating once a day after each game is a possibility.

  3. The data of each game is related to the game and the players, but is it often the same query as a certain one? If not, but only for statistical services, it is also good to put it in a separate collection.

  4. Indices can help you find data faster, but they can’t help you reduce the resulting data set. After the data model is designed, it is natural to choose an index.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!