You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I am using mongoose. Here i have an requirement that i need to fetch student document when matches to its classRoomName name and rollNo. Here below is my student and classRoom schemas as follows:
1.student
===========
new Schema({
rollNo:{type:Number, required:true},
name:{type:String},
classRoomRef:{type:Schema.Types.ObjectId,ref:'classRoom', required:true}
});
2.classRoom
============
new Schema({
classRoomNo:{type:Number},
classRoomName:{type:String}
});
I managed to get student document with rollNo . i have written the mongoose query like this below:
student.findOne({rollNo:"xxx"}),function(err,data){
//printing data
});
Now I need to retrieve student document based on classRoomName , i written below query but not working. Giving null.
student.findOne({rollNo:"xxx","classRoomRef.classRoomName":"yyy"}).populate("classRoomRef").exec(function(err,data){
//printing data
});
Kindly help me.
The text was updated successfully, but these errors were encountered:
Not possible to do that. .populate() is not a join, the above query simply finds students and then executes a separate query for the students' corresponding classRoomRef. If you want to query students by classRoomName, store classRoomName in the student doc.
Hi,
I am using mongoose. Here i have an requirement that i need to fetch
student
document when matches to itsclassRoomName
name androllNo
. Here below is mystudent
andclassRoom
schemas as follows:I managed to get
student
document withrollNo
. i have written the mongoose query like this below:Now I need to retrieve
student
document based onclassRoomName
, i written below query but not working. Givingnull
.Kindly help me.
The text was updated successfully, but these errors were encountered: