Storing data question

Hi.

This is probably a basic question, but I thought I’d ask just in case i’m over thinking things.

I have Players that are part of Teams. So in the Team collection I have an array property with a list of all the PlayerID’s that are part of that team.

My question is: is it better practice to also create an array property for the Player that stores what teams the player belongs to.

I imagine that as the Team collection grows larger, it’ll take longer to find the teams that the player is associated with, and it would be quicker to just grab the ID’s of the teams from the user profile which will likely have been loaded already. But if I do it this way I have to make sure that if I’m deleting a team out of the collection that I’m always updating the user profile as well.

Am I on the right direction here?

This is correct.
This topic is called normalization/denormalization.
What you gain on the performance front with data duplication (denormalization), you lose it on the complexity front since you have to remember to update multiples occurences at once. This is a tradeoff you have to make, and there is no definitive answer on this.
“nosql” database like mongo tend to favor denormalization
"sql" database like oracle tend to favor normalization, althought both approaches are possible with both paradigms.

1 Like

Perfect.

Thanks for the reply!