【发布时间】:2019-09-22 23:03:05
【问题描述】:
我正在尝试为 user 创建不同类型的注册。我为用户收集了三个集合。我一直在参考教师和学生的用户集合,因为我需要获取电子邮件和密码。
如果教师注册包括电子邮件、密码、名字、姓氏等,则有一个集合。
如果学生注册包括电子邮件、密码、名字、姓氏等,则有另一个集合。
我们所有的邮箱和密码都将是一个集合
用户 - 表/集合 - 电子邮件:test@gmail.com - 密码:asdfasdf
学生 - 表/集合 - 名字:'sujon'
老师 - 表/集合 - 名字:“sujon”
const UserSchema = mongoose.Schema({
email: {
type: String,
required: true,
},
password: {
type: String,
required: true,
},
isAdmin: {
type: Boolean,
default: false,
},
})
const StudentSchema = mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'user',
},
firstname: {
type: String,
},
lastname: {
type: String,
},
photo: {
type: String,
},
education: {
type: String,
},
birth: {
type: Date,
},
sex: {
type: Boolean,
},
})
const TeacherSchema = mongoose.Schema({
user: {
type: mongoose.Schema.ObjectId,
ref: "user"
},
firstname: {
type: String
},
lastname: {
type: String
},
photo: {
type: String
},
designation: {
type: String
},
birth: {
type: Date
},
sex: {
type: Boolean
}
});
如何实现数据库设计
【问题讨论】:
标签: mongodb mongoose mongodb-query mongoose-schema