Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb Mongoose是否参照现有文档保存文档?_Mongodb_Mongoose_Mongodb Query - Fatal编程技术网

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
    }
});
在引用现有学生时,如何进行查询以将新子任务插入数据库