【发布时间】:2021-07-18 02:23:25
【问题描述】:
我正在做我最后一年的项目,新的 MERN 堆栈面临在 mongoDB 文档中创建引用的问题。 使用两个模型和一个控制器将数据保存在不同的文档中,同时如何将 student_id 保存为 parentdata 文档中的引用。
AdmissionController.js
const newStudent = new studentModel({
s_fname,
s_lname,
gender,
age
})
const ParentData = new parentModel({
fatherName,
father_cnic,
FatherDesignation,
fatherMobile,
motherName
})
newStudent.save()
ParentData.save()
在父模型中
student_id: { type: Schema.Types.ObjectId, ref:'student'}
【问题讨论】: