MongoDB数据库关系

时间:2014-10-03 21:24:57

标签: mongodb mongodb-.net-driver mongodb-query

我刚刚开始在MongoDB中构建数据库。我有2个表,Teams和Fixtures,每个Fixture文档应该有2个指向Fixtures表的链接,一个HomeTeamId和一个AwayTeamId。这是正确的方法吗?

团队:

{
    "_id": {
        "$oid": "542978c4e4b0e67da1edc7f3"
    },
    "TeamName": "Arsenal",
    "BadgeSmall": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Small/arsenal.png",
    "BadgeLarge": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Large/arsenal.png",
    "TeamImage": "http://footballcomps.azurewebsites.net/Content/Images/Teams/arsenal.png",
    "Formation": "http://footballcomps.azurewebsites.net/Content/Images/Formations/arsenal.png"
}

{
    "_id": {
        "$oid": "542979c3e4b0e67da1edc807"
    },
    "TeamName": "Aston Villa",
    "BadgeSmall": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Small/astonvilla.png",
    "BadgeLarge": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Large/astonvilla.png",
    "TeamImage": "http://footballcomps.azurewebsites.net/Content/Images/Teams/astonvilla.png",
    "Formation": "http://footballcomps.azurewebsites.net/Content/Images/Formations/astonvilla.png"
}

{
    "_id": {
        "$oid": "542c45eee4b0413a3dd4d43e"
    },
    "TeamName": "Crystal Palace",
    "BadgeSmall": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Small/crystalpalace.png",
    "BadgeLarge": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Large/crystalpalace.png",
    "TeamImage": "http://footballcomps.azurewebsites.net/Content/Images/Teams/crystalpalace.png",
    "Formation": "http://footballcomps.azurewebsites.net/Content/Images/Formations/crystalpalace.png"
}

赛程:

主队:Aston Villa,客队:阿森纳:

{
    "_id": {
        "$oid": "542f0dfbe4b0413a3dd4ead4"
    },
    "Date": "2014-09-20",
    "HomeTeamId": "542979c3e4b0e67da1edc807",
    "AwayTeamId": "542978c4e4b0e67da1edc7f3",
    "HomeTeamScore": 0,
    "AwayTeamScore": 3,
    "HomeTeamScorers": "",
    "AwayTeamScorers": "Ozil 33,Welbeck 34,Cissokho 35 (OG)"
}

主队:阿森纳,客队:水晶宫:

{
    "_id": {
        "$oid": "542f0f54e4b0413a3dd4ead8"
    },
    "Date": "2014-08-16",
    "HomeTeamId": "542978c4e4b0e67da1edc7f3",
    "AwayTeamId": "542c45eee4b0413a3dd4d43e",
    "HomeTeamScore": 2,
    "AwayTeamScore": 1,
    "HomeTeamScorers": "Koscielny 45,Ramsey 90",
    "AwayTeamScorers": "Hangeland 35"
}

1 个答案:

答案 0 :(得分:0)

我个人建议在游戏中嵌入团队对象团队及其图标在一个赛季内不太可能发生变化。拨打1个电话而不是3个电话。

{
    "_id": {
        "$oid": "542f0dfbe4b0413a3dd4ead4"
    },
    "Date": "2014-09-20",
    "HomeTeamId": "542979c3e4b0e67da1edc807",
    "AwayTeamId": "542978c4e4b0e67da1edc7f3",
    "HomeTeamScore": 0,
    "AwayTeamScore": 3,
    "HomeTeamScorers": "",
    "AwayTeamScorers": "Ozil 33,Welbeck 34,Cissokho 35 (OG)",
    "HomeTeam" : {
        "_id": {
            "$oid": "542979c3e4b0e67da1edc807"
        },
        "TeamName": "Aston Villa",
        "BadgeSmall": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Small/astonvilla.png",
        "BadgeLarge": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Large/astonvilla.png",
        "TeamImage": "http://footballcomps.azurewebsites.net/Content/Images/Teams/astonvilla.png",
        "Formation": "http://footballcomps.azurewebsites.net/Content/Images/Formations/astonvilla.png"
    },
    "AwayTeam" : {
            "_id": {
                "$oid": "542978c4e4b0e67da1edc7f3"
            },
            "TeamName": "Arsenal",
            "BadgeSmall": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Small/arsenal.png",
            "BadgeLarge": "http://footballcomps.azurewebsites.net/Content/Images/Badges/Large/arsenal.png",
            "TeamImage": "http://footballcomps.azurewebsites.net/Content/Images/Teams/arsenal.png",
            "Formation": "http://footballcomps.azurewebsites.net/Content/Images/Formations/arsenal.png"
    }
}