【发布时间】:2019-12-11 18:02:23
【问题描述】:
我有两个模型,病人和医生。当用户登录时,无论是医生还是病人,只有一个路由运行后端的登录功能。但我不明白的是如何查询,以便使用单个查询在患者和医生的集合中进行搜索。
这是医生模型:
const doctorSchema = new Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
},
practitionerLicense: {
type: String,
required: true
}
});
module.exports = Doctor = mongoose.model("doctors", doctorSchema);
还有患者模型:
const patientSchema = new Schema({
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
date: {
type: Date,
default: Date.now
}
});
module.exports = Patient = mongoose.model("patient", patientSchema);
现在我想要类似下面的伪代码,其中用户可以是基类或其他东西。
Users.findOne({email}).then(...)
我遇到了许多其他类似的问题,但看到了我认为不适合我的情况的填充方法。有什么建议吗?
【问题讨论】:
标签: javascript mongoose