简体   繁体   English

使用NodeJS的MongoDB集合

[英]MongoDB collections with NodeJS

I am doing my own personal project to learn new technologies (angular, nodejs, express, mongodb) . 我正在做自己的个人项目,以学习新技术(angular, nodejs, express, mongodb) I have login/register users (collection: users) , real sport players ( collection: players) . 我有login/register用户(collection: users) ,真正的体育玩家( collection: players) Now, i am doing user_teams (collection: user_team) and there i have all positions like goalkeeper, midfielder, attacker . 现在,我正在做user_teams (collection: user_team) ,在那里我有所有位置,如goalkeeper, midfielder, attacker So User create User_team and in user_team he will choose players from collection players. 因此,用户创建User_team,并在user_team中,他将从集合玩家中选择玩家。

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? 我应该将其拆分,因此玩家,user_teams,user或一个集合用户中我应该具有user_team?

Thanks. 谢谢。

The document schema may fit your requirements. 文档架构可能符合您的要求。 Create only one collection userTeam with the following schema 使用以下架构仅创建一个集合userTeam

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM