【发布时间】:2021-01-13 14:57:57
【问题描述】:
我有一个用户架构。在保存文档时,对于文档中的每个嵌套对象(quizHistory、record 和响应),猫鼬会自动添加 _id 字段。 For ref- quizHistory path
const userSchema = new Schema({
firstName: { type: String, required: true ,trim:true},
lastName:{ type: String, required: true ,trim:true},
email: { type: String, unique: true, required: true },
isUser: { type: Boolean, default: true },
password: String,
quizHistory: [{
quizId: { type: Schema.Types.ObjectId, ref: 'Quiz' },
record: [{
recordId:{ type: Number},
startTime: { type: Date },
responses: [{
quesId: { type: Schema.Types.ObjectId, ref: 'Question' },
answers: [Number]
}],
score: Number
}],
avgScore: Number
}]
})
【问题讨论】:
标签: mongodb mongoose nosql mongoose-schema