Mongodb – Database Design for NoSQL Fantasy Baseball League

database-designmongodbnosqlschema

I am trying to create a proper schema to place scraped data into, using a MongoDB database.

Currently it looks like

Team {
    id : id,
    name : String,
    teamLink : String,
    username : String,
    userLink : String,
    league : Number,
    Rank : {
        global : Number,
        division : Number
    },
    Points : {
        global : Number,
        division : Number
    }
    Stats : [{
        desc : String,
        value : String,
        globalRank : Number,
        globalPts : Number,
        divRank : Number,
        divPts : Number
    }]
}

League {
    id : Number,
    name : String,
    link : String,
    division : Number,
    acrive : Boolean
    rankings : [{
        week : Number,
        ranks : [{
            team : String,
            position : Number,
            points : Number
        }]
    }]
}

The problem is that a lot of this makes it hard to quickly rank over something as simple as a single stat (e.g. HR). So I am trying to better understand on how to model the data to say, quickly sort over HRs or easily obtain the rankings. I come from a relational db background so I am having a hard time adjusting without joins.

Thank you

Best Answer

Team {
    id : id,
    name : String,
    teamLink : String,
    username : String,
    userLink : String,
    league : Number,
    Stats : [{
        desc : String,
        value : String,
        globalRank : Number,
        globalPts : Number,
        divRank : Number,
        divPts : Number,
        year:Number
    }]
}

League {
    id : Number,
    name : String,
    link : String,
    division : Number,
    acrive : Boolean
}

rankings : {
            week : Number,
            league_id: Number,
            year: Number,
            ranks : [{
                team_id : Number,
                position : Number,
                points : Number
            }]
        }

match {
       id : Number,
       league : Number
       team_visit : Number,
       team_ext : Number,
       ining : Number,
       time_start : Datetime,
       time_game : Number,
       team_visit_score : Number,
       team_ext_score : Number    
}

EDIT: explain schema.

  • First is necessary separate all stats for team in a interval time, because changes in time for season, years, stats, etc...

  • Add the match documents, for each match a document. Separate all for documents, League, Teams, Ranks, is better for search and relation with others team in match, rank...

  • And the solution is MySQL I'm not so sure about that, because if you have a lots data in match, league, teams, ranks... Is Better documents with all stats of any team, or all rank in any interval time because in MySQL you need JOINS for that.