Mongodb Mongoose是否参照现有文档保存文档?
我正在编写一个应用程序,让学生协作并跟踪他们完成任务所花费的时间 下面我有两个模式 学生:Mongodb Mongoose是否参照现有文档保存文档?,mongodb,mongoose,mongodb-query,Mongodb,Mongoose,Mongodb Query,我正在编写一个应用程序,让学生协作并跟踪他们完成任务所花费的时间 下面我有两个模式 学生: const studentSchema = new mongoose.Schema({ _id: mongoose.Schema.Types.ObjectId, studID: { type: String, min: 8, max: 8, required: true }, units: [{
const studentSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
studID: {
type: String,
min: 8,
max: 8,
required: true
},
units: [{
type: mongoose.Schema.ObjectId,
ref: 'Unit'
}],
fname: {
type: String,
required: true,
},
lname: {
type: String,
required: true
}
});
任务:
const subtaskSchema = new mongoose.Schema({
_id: mongoose.Schema.Types.ObjectId,
name: {
type: String,
required: true
},
estTime: {
type: Number,
default: 0
},
status: {
type: String,
required: true,
default: 'Inactive'
}
,
students: [{ //students involved in task
type: mongoose.Schema.ObjectId,
ref: 'Student'
}],
totalTime: {
type: Number,
default: 0
}
});
在引用现有学生时,如何进行查询以将新子任务插入数据库