Я использую mongoose
. Я пытался добавить модели в
ProductController.js:
const student = require('../models/studentModel');.populate('student_list')
но я все равно получаю тот же результат.
productModel.js
{
lectureProductId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Lecture',
}
}
lectureModel.js
{
task_list: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'task'
}],
student_list: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'student'
}],
teacher: {
type: mongoose.Schema.Types.ObjectId,
ref: 'teacher', required: true,
},
}
productController.js
productModel.find()
.populate('lectureProductId')
.populate('taskProductId')
.then(product => {
res.json({
status: 'success',
message: 'products retrieved successfully',
data: product
});
})
lectureController.js
lectureModel.find()
.populate('teacher')
.populate('task_list')
.populate('student_list')
.then(lecture => {
res.json({
status: 'success',
message: 'Lectures retrieved successfully',
data: lecture,
});
})
При отправке запроса я вижу:
"lectureProductId": {
"keywords": [ "MATLAB", "BİSECTİON", "NEWTON-RAHSON" ],
"task_list": [ "5d26d617454d23000665421c", "5d26d617454d230006654217", "5d26d617454d23000665421b", "5d26d617454d23000665421a", "5d26d617454d230006654218" ],
"student_list": [ "5d26d615454d230006654206", "5d26d615454d230006654207", "5d26d615454d230006654208", "5d26d615454d23000665420c", "5d26d615454d23000665420d", "5d26d616454d23000665420e", "5d26d616454d23000665420f" ],
"_id": "5d26d617454d230006654221",
"name": "Numerical Analysis",
"programmingLanguages": "MATLAB",
"description": "MATLAB for easy level",
"teacher": "5d26d616454d230006654215", "__v": 0
}
Как посмотреть student_list
с другими полями?
"student_list": [
"5d26d615454d230006654206",
"5d26d615454d230006654207",
"5d26d615454d230006654208",
"5d26d615454d23000665420c",
"5d26d615454d23000665420d",
"5d26d616454d23000665420e",
"5d26d616454d23000665420f"
]