Разработка схемы MongoDB с помощью мангуста - PullRequest
0 голосов
/ 14 июля 2020

Я создаю проект - где пользователи могут создавать проекты и назначать задачи каждому проекту. У меня есть две коллекции - одна для пользователей и одна для проектов. Мои схемы выглядят так: 1) пользователь -

const userSchema = new Schema({
    firstName: {
        type: String,
        required: true,
        minlength: 2,
        trim: true
    },
    lastName: {
        type: String,
        required: true,
        minlength: 2,
        trim: true
    },
    email: {
        type: String,
        required: true,
        trim: true,
        lowercase: true,
        validate(email) {
            if(!validator.isEmail(email)) {
                throw new Error('Email is invalid')
            }
        }
    },
    password: {
        type: String,
        required: true,
        trim: true,
        minlength: 7,

    },
    activationKey: {
        type: String,
        required: true,
    },
    active: {
        type: Boolean,
        required: true,
        default: 0
    }
})
Проект
const projectSchema = new Schema({
   name: {
       type: String,
       required: true,
       minlength: 2,
   },
   description: {
       type: String,
   },
   _user: {
       type: Schema.Types.ObjectId, 
       ref: 'User' 
   },
   tasks: [{
       name: {type: String, required: true, minlength: 2},
       completed: {type: Boolean, required: true, default: 0}
   }]
})

Это правильный дизайн БД или он очень плохой? Должны ли задачи быть отдельной моделью (но тогда, вероятно, будет очень сложно объединить три коллекции. Или я должен все вложить в модель User?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...