node.js - Nested For loop with mongodb async callbacks/synchronus -


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

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -