SQL - .
, (// ).
, , , degree_id (branch_id/subject_id) ,
select * from syllabus where degree_id = ?
select * from syllabus where branch_id = ?
, _, ,
select s.* from syllabus s
join branch b on b.branch_id = s.branch_id
join subject su on su.subject_id = s.subject_id
where b.degree_id = ?
, , _, .
MongoDB.
SQL MongoDB: 4 4 .
{
degree_id : ...
degree_name : ...
}
{
branch_id : ...
branch_name : ...
degree : {
degree_id : ...
degree_name : ...
}
}
, , , , , .
MongoDB JOINS, . , , _id ( , SQL), , .
[
{
_id : ObjectId('syllabus_id_1'), //_id or syllabus_id but MongoDB adds an _id field automatically,
syllabus_name : 'syllabus1',
sort_note : 'a note',
attachment : 'my attachment',
semester : 'semester1',
degree : {
degree_id : ObjectId('degree_id_1'),
degree_name : 'degree1'
},
branch : {
branch_id : ObjectId('branch_id_1'),
branch_name : 'branch1',
degree : {
degree_id : ObjectId('degree_id_1'),
degree_name : 'degree1'
}
},
subject : {
subject_id : ObjectId('subject_id_1'),
subject_name : 'subject1',
subject_code : 'code',
semester : 'semester1',
degree : {
degree_id : ObjectId('degree_id_1'),
degree_name : 'degree1'
}
}
}
]
, , ,
syllabus.find({'degree.degree_id':ObjectId('degree_id_1'), 'degree.degree_name':'degree1'})
syllabus.find({'branch.branch_id':ObjectId('branch_id_1'), 'branch.branch_name':'branch1'})
_id, :
[
{
_id : ObjectId('syllabus_id_1'),
syllabus_name : 'syllabus1',
sort_note : 'a note',
attachment : 'my attachment',
semester : 'semester1',
degree : ObjectId('degree_id_1'),
branch : ObjectId('branch_id_1'),
subject : ObjectId('subject_id_1'),
}
]
id,
syllabus.find({degree:ObjectId('degree_id_1')})
syllabus.find({degree:ObjectId('branch_id_1')})
, , . , .
, .
, JOINS, , - , Mongoose. , , , MongoDB. MongoDB: -)
, , - .