Lukas
Lukas

Reputation: 83

MongoDB collections with NodeJS

I am doing my own personal project to learn new technologies (angular, nodejs, express, mongodb). I have login/register users (collection: users), real sport players (collection: players). Now, i am doing user_teams (collection: user_team) and there i have all positions like goalkeeper, midfielder, attacker. So User create User_team and in user_team he will choose players from collection players.

What is the best way to do? I should have it split, so players, user_teams, user, or in one collection user I should have user_team?

Thanks.

Upvotes: 0

Views: 54

Answers (1)

Mani
Mani

Reputation: 1549

The document schema may fit your requirements. Create only one collection userTeam with the following schema

{
    "user" : "user1",
    "team" : [ 
        {
            "playerName" : "Player1",
            "role" : "goalkeeper"
        }, 
        {
            "playerName" : "Player2",
            "role" : "midfielder"
        }, 
        {
            "playerName" : "Player3",
            "role" : "attacker"
        }
    ]
}

Upvotes: 2

Related Questions