2014-10-03 52 views
0

我剛剛開始在MongoDB中構建數據庫。我有2張桌子,球隊和賽程,並且每個Fixture文件應該有2個鏈接到Fixtures表,一個HomeTeamId和一個AwayTeamId。這是做到這一點的正確方法嗎?MongoDB數據庫關係

團隊:

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

回答

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