【发布时间】:2021-02-24 19:46:34
【问题描述】:
我有两个schema Teacher,
const TeacherSchema = mongoose.Schema(
{
name:String
_id: ObjectId
})
学生
const StudentSchema = mongoose.Schema(
{
name:String
_id: ObjectId
})
我有评论模式
const CommentSchema = mongoose.Schema(
{
description: String,
user_type:String // Student or Teacher
user_id: ObjectId
})
如何根据user_type 填充CommentSchema,例如。 if user_type === Teacheruser_id 来自TeacherSchema
【问题讨论】:
标签: mongodb mongoose mongoose-schema mongoose-populate