I can't seem to figure out how to pass objects from arry in collection.find('{pid: patient[0][i].pid}'). it is a concatenation problem.
router.get('/fullsurveys/:doctor', async (request, res) => {
try{
const doctor = JSON.parse(request.params.doctor);
posts = [];
patients = [];
patients.push(await Patient.find(doctor));
for(var i = 0; i < patients[0].length; i++){
if(patients[0][i].patientstate == true){
posts.push(await FullSurvey.find('{pid: patient[0][i].pid}'));
}
}
res.json(posts);
}catch(err){
res.json({message: err});
}
});
You are passing stringified json in find function & the variable name in FullSuvery.find seems to be wrongs, you have patient[0][i].pid
when it should have been patients[0][i].pid
Change you code to
router.get('/fullsurveys/:doctor', async (request, res) => {
try{
const doctor = JSON.parse(request.params.doctor);
posts = [];
patients = [];
patients.push(await Patient.find({doctor:doctor}));
for(var i = 0; i < patients[0].length; i++){
if(patients[0][i].patientstate == true){
posts.push(await FullSurvey.find({pid: patients[0][i].pid}));
}
}
res.json(posts);
}catch(err){
res.json({message: err});
}
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.