【问题标题】:MongoDB database relationshipsMongoDB数据库关系
【发布时间】:2014-10-03 21:24:56
【问题描述】:

我刚刚开始在 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"
}

夹具:

主队:阿斯顿维拉,客队:阿森纳:

{
    "_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"
}

【问题讨论】:

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


    【解决方案1】:

    我个人建议在游戏中嵌入团队对象 团队及其图标不太可能在一个赛季内发生变化。拨打 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"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 2013-09-29
      相关资源
      最近更新 更多