我有以下模式:
//Schema A
const evaluationSchema = new Schema({
"testId": { type: Number, unique: true },
"testCaseName": { type: String },
"marks": { type: Number }
})
//Schema B
const resultSchema = new Schema({
"empId": { type: Number, index: { unique: true } },
"score": { type: Number, default: 0 },
"questionPaper": { type: String },
"evaluationReport": [evaluationSchema], //Embeddeding Schema A
"evaluatedOn": { type: Date, default: new Date() },
"updatedOn": { type: Date, default: new Date() }
})
//Schema C
const batchReportSchema = {
"fa": [{
"faNo": { type: Number, required: [true, 'Required field'] },
"result": [resultSchema] //Embedding Schema B
}]
};
const schema = mongoose.Schema(batchReportSchema , { collection:
batchName });
您会注意到,这是带有嵌入式子文档的架构。当我插入值时,唯一属性不会应用于empId和testId属性。
我在做什么错?任何指示或建议都会有所帮助。