MongoDB store weekly data

mongodb

I am trying to think of the best way to store my applications data in weekly chunks.

The app is a basketball statistics app, after all the games are finished for example in week one I would like to store the tracked data into a week 1 database.

Right now all the data is stored using a REST api and the app has 2 collections, one for players and one for teams.

The client side pulls in the teams collection then pulls in the players collection.

I am just lost on how I would go about separating data by weekly, so that the main client side still pulls in the teams and players but in week two has a fresh copy, but in another area in my app I can still pull old data by week.

I hope this is clear enough, I would greatly appreciate some insight.

Best Answer

have you looked at having Historic Players and Historic Team collections?

Then if you wanted stats about the players at the time, you'd probably want to copy out the current players on the team in your historic games documents. You'd probably want to store that as an array in the Historic Games table as the current players list might be different than the players from last week/year.

Keep the position of the players in the document in mind so you can end up using proper indexes.

historic players
_id: jfoi23j8xx
PlayerID:Bo Jackson
weekinfo<array or tags> 
[week 1- hits:30, misses:3, bunts:7, TeamID: LA Raiders], 
[week2 - hits:17, misses:2, bunts:3, TeamID: Kansas City Royals]


historic teams:
_id:10u40o321js
TeamID: LA Raiders
Weekinfo<array or tags>
[week 1 - consolidated hits: 73, misses: 12],
[week 2 - consolidated hits:65, misses: 16]

Something like that might be a good start. Does it meet your requirements? You might want to have your app handle the aggregation but that's up to you.