node.js - Empty moongose result in nested query -


ok, here code:

router.get('/',middleware.isloggedin, function(req, res){   var clave = req.query.id;   students.findbyid(req.params.id).exec(function(err,foundstudent){     if(err){       console.log(err);     }else{       var estudiante=foundstudent.matriculat0;       var modelo=foundstudent.modelo;       horarios.find({matricula:estudiante,clavemateria:clave}).exec(function(err,foundhorario){         if(err){           console.log(err)         }else{           var grupo=foundhorario[0].crn;           grades.find({crn:grupo}).exec(function(err,foundgrade){             if(err){               console.log(err);             }else{               var pagina="grade/"+modelo+"/"+clave;               res.render(pagina,{horario:foundhorario, student:foundstudent, grade:foundgrade}); }})}})}})}); 

basically i'm working 3 diferent models, students, schedule , grades. access grades of each subject per students first selected student , take school id number (matricula) , model belongs (there two).

once have in school schedule student subjects using "matricula" , "clave" (the subject key code" got request. once 7 subjects students specic subject code (crn) can load it's grades in ejs template (every subject has different grading system...)

so, works great, rendering of page , looking students , schedule, problem last query, foundgrade comes empty when same query in mongo console correct result.

 var grupo=foundhorario[0].crn 

gives correct result, subject key in form of string , in grade model subject key (crn) string. have made sure collection name in plural that's not problem either, ideas?

this not answer, think can continue explaining/solving trouble here!

router.get('/',middleware.isloggedin, async (req, res) => {   try{        let clave  = req.query.id;         let foundstudent = await students.findbyid(req.params.id);         let estudiante = foundstudent.matriculat0;         let modelo  = foundstudent.modelo;         let foundhorario = await horarios.find({             matricula   :estudiante,             clavemateria:clave         });         let grupo  = foundhorario[0].crn;         let foundgrade = await grades.find({crn:grupo});         let pagina="grade/"+modelo+"/"+clave;           return res.render(pagina,{                   horario : foundhorario,                   student : foundstudent,                    grade   : foundgrade         });    }catch(err){         return res.status(400).json(err);    } }); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -