为什么没有在猫鼬模型上设置属性

时间:2020-02-28 16:03:19

标签: javascript node.js mongodb mongoose

我尝试将带有引用的模型保存到名为class的其他模型中。我创建属性后,属性就在模型中,但是当我保存它时,类消失了。

这是保存代码

const newStudent = class_id ? new _Student({vkId, class: class_id}) : new _Student({vkId});
//newStudent have class property 
await newStudent.save();//but there it is dissapear
return await DataBase.getStudentBy_Id(newStudent._id);

class_id是文档中的objectId

这就是我在模式中定义类属性的方式

class: {
        type: mongoose.Schema.ObjectId,
        ref: "Class",
        autopopulate: true
    }

帮助。

0 个答案:

没有答案