0

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.

1 Answer 1

1

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.

4
  • I like the idea, but in my experience backbone js which is what I am using client side does not play very well with nested models, and I think I would have to do a lot of reconstructing. I don't know if it's optimal to create a brand new collection, but I am leaning towards that, I am not sure how I can aggregate a new collection, I would need to read up on the docs. Commented Dec 3, 2014 at 22:39
  • So basically should I be looking into aggregating a new collection? +1 for the answer though, it's good I considered something like this but I prefer to avoid nested collections. Commented Dec 3, 2014 at 22:40
  • 1
    You might not need to aggregate the historic teams and keep that info in mongodb, you could also just do the aggregation in the app layer and avoid the consolidated document holding historic teams info. Instead of tags just use a group of arrays and that should be easier for backbone js to query IMO. Just a thought though, I'm sure there's lots of great ways to do this. Commented Dec 3, 2014 at 22:43
  • Sorry got caught up last night, okay what I was thinking was having a user hit complete week and saving that week. I just need to figure out how to create a new table or I guess mongoDB would call it a collection. The way I create the main collection is using a schema but I am not sure how to create one without defining a schema, if that makes sense. Commented Dec 4, 2014 at 21:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.