如何解决从collection.find中的数组传递对象的问题
我似乎无法弄清楚如何从collection.find('{pid:Patient [0] [i] .pid}')中的arry中传递对象。这是一个串联问题。
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});
}
});
解决方法
您要在find函数中传递字符串化的json,而FullSuvery.find中的变量名称似乎是错误的,您应该将patient[0][i].pid
设置为patients[0][i].pid
将您的代码更改为
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});
}
})
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。