node.js - Nested For loop with mongodb async callbacks/synchronus -
this question has answer here:
this.getexams=function(callback){ exam.find({},'examname examdate groupid',function(err,exams){ if(err) throw err; // console.log(exams); for(var key1 in exams){ var groupsname=[]; //console.log(exams[key1].groupid.length,"groupid") for(var i=0;i<exams[key1].groupid.length;i++){ //console.log(exams[key1].groupid[i]); group.findbyid(exams[key1].groupid[i],'groupname',function (err,group){ if(err) throw err console.log(group.groupname,"group"); groupsname.push(group.groupname); }); }.then(function(){ console.log(groupsname); exams[key1].groupsname=groupsname; }); }.then(function(){ callback(exams); }); }); }
this general function want run not async group.findbyid work after loops plz tell me solution
Comments
Post a Comment