例如我现在做一个回复功能,这个回复功能想整合到 movie模型和document模型(而不是两个回复功能重复开发),那么该怎么做呢?
var CommentSchema = new Schema({ movie: {type: ObjectId, ref: 'Movie'}, //被评论的电影id,这里的ref能指定两个吗? from: {type: ObjectId, ref: 'User'}, content: String })
回复 (2)
R
new Schema {
targetType:
type: String
enum: ['Movie', 'Document']
target:
type: ObjectId
refPath: 'targetType'
}
V
引用 ravenwang
@ravenwang 厉害,我试试
参与回复
登录后即可参与回复。登录