const mongoose = require('mongoose'); const questionSchema = new mongoose.Schema({ type: { type: String, enum: ['single', 'multiple', 'text'], required: true }, question: { type: String, required: true }, options: [String], answer: mongoose.Schema.Types.Mixed, // 可以是索引、索引数组或字符串 score: { type: Number, required: true } }); const examSchema = new mongoose.Schema({ title: { type: String, required: true }, description: String, duration: { // 考试时长(分钟) type: Number, required: true }, questions: [questionSchema], createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true }, createdAt: { type: Date, default: Date.now }, isActive: { type: Boolean, default: true } }); module.exports = mongoose.model('Exam', examSchema);