0

I am just starting off with NoSQL structures, using Firebase in particular, which is hugely different then MySQL or rational DBs.

I am developing an app that will list sport games; the users can retrieve a list of all the games and select which one they would like to participate in.

The list of games spans, or at least will span multiple years, ex games in 2012, 2013, 2014, 2015, 2016 (present), 2017 (future) etc...

The table structure in my MySQL table has the following primary key combo (gameid, yearid, sportType); the reason being each new year instead of just incrementing the gameid, it would restart at 1 which needed the yearid to make it unique and the sportType since it could entries for baseball, football, hockey etc...

I am created the JSON structure and I guess I am questioning myself and need help to if you could just check if it is denormalized or if I can improve it somehow?

I think I am following rational methodology but I was thinking of have the following:

{
  "games" : {
  "year" : {
  "sportType" : {
       "desc" : "Week 1 ",
       "teamid" : 123
       "gameid" : 11111,
       etc...
       }
    } 
},
"year" : {
  "sportType" : {
       "desc" : "Week 1 ",
       "teamid" : 223
       "gameid" : 22222,
       etc...
       }
    } 

It kind of follows the primary indexing I did for MySQL but do I need to is the question!? I think I don't but I want other opinions since I am new to this...

I am thinking that I should just follow :

{
  "games" : {
    "gameid" : {
        "desc" : "Week 1 ",
        "teamid" : 123
        "sportType" : "football",
        "year" : 2016
           etc...

Can someone please help guide me?!

1 Answer 1

1

I think you are on the right way. But if you have an object like teamDetail as follow u should move the details another node and point it inside teamDetail.

{
  "games" : {
    "gameid" : {
        "desc" : "Week 1 ",
        "teamid" : 123
        "sportType" : "football",
        "year" : 2016
         "teamDetail": {
          "name": team1,
          "country": c1,.. etc
          }
           etc...

Denormalized version of the above for teamDetail object.

{
  "games" : {
    "gameid" : {
        "desc" : "Week 1 ",
        "teamid" : 123
        "sportType" : "football",
        "year" : 2016
         "teamDetail": {
          "team1id": true,
          "team2id": true, ...etc...
          }
           etc...

teamDetails:{

 "team1id": {
          "name": team1,
          "country": c1,.. etc
          }
 "team2id": {
          "name": team2,
          "country": c2,.. etc
          }

}

So I was thinking of having like you outlined the following:
{ "team" : { "teamid" : { "name" : "blah ", "teamcity" : "L.A." etc... and in the game JSON reference the teamid in order to pull the team details but in include it as part of the actual game definition as it would be repeated and in the instance the team changes name or city it would have to be changed in all the entries of Games? Am I right in doing so!?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.