Storing a collection of collections

I am creating an app to manage sports teams.

When a coach is logged in, he has the ability to create a temporary collection of players (by selecting individual players that already exist in the Players collection) which is then exported to a PDF teamsheet.

teamSheet = new Meteor.Collection(null);

I would like to allow coaches to save this teamsheet to his profile for future reference, and be able to create new teamsheets for every game. So I changed the code to:

teamSheet = new Meteor.Collection('teamsheet');

But that will obviously return the exact same teamsheet every time the app loads.

Can anyone provide advice on how to store this kind of collection?

depending on how long it needs to be stored, a session variable… you could use it to do immediate stuff like print the pdf, then you could push the variable into a pastTeamSheets collection that has a reference to the coach’s userId?

1 Like

are you sure a separate collection for each team would be the best approach? in your scenario you seem to be thinking that each collection is a team and in it each document is a player?

your case sounds more appropriate for a collection of teams with each document being a team with players either linked or embedded in each team document. without more context, that would be the obvious choice.

The reply to your question might be more to find a way to architecture your data in another way.

Could you give us more details about the structure you want to build?

Yeah it only really needs to be stored for the duration of the session. Looking at this stackoverflow question, I can do:
sessionStorage.setItem() to store the string representation of the object…then when you need it sessionStorage.getItem() and then $.parseJSON()

By embed are you referring to reactive joins? In the case of a teams collection, should I use a join function to associate the individual players to the team document?

by embedding I was thinking in terms of addToSet etc…

but if you don’t want to store for reference and resilience, etc, and just want to do it in memory and not use collections and documents at all, yeah, you can just work with a reactive-dict, nested object or array or similar for temporary use. just my 2c.

1 Like

Thanks, I will go through those docs.

Besides the user accounts, the app only has two collections: Players & Teamsheets
Before a game, a coach goes through his list of players to select a team. This team is (so far) a temporary collection that is displayed to the coach on the /teamsheets url.

Once he clicks Export Teamsheet the data in the collection is passed to a PDF script (in this case phantom.js) to output the PDF. At this point the teamsheets collection is empty again, so he can make new team selections.

But the coach might have made a mistake & wants to swap one player out for another, I’d like to let him access previously created teamsheets, edit them & then export to PDF again.