javascript - Node.js render json map from mongodb -


i want show data json map express

this code

var b = det.map(function(h) {     var soalid = h.id_soal;     var idarray = [ ];     (var = 0; < soalid.length; i++) {          soal.findone({             _id: soalid[i]         }, function (err, sol) {              idarray.push(sol);             console.log("ping:" + idarray);         });      }     res.render('ujian/viewdetail',{ujian: iduji, detail: det, soal: idarray, title: 'lihat form ujian'}); }); 

i have try run console data json not showing on express (web).

and have json file :

ping:{       _id: 58516fc32aeffd103cdda179,      jurusan: 'ipa',      matapelajaran: 'fisika',      soal: 'agae',      jawabana: 'hjg',      jawabanb: 'h',      jawabanc: 'hbh',      jawaband: 'hbh',      jawabane: 'h',      kuncijawaban: 'hb',      __v: 0  }, {      _id: 585a95167467c5185e2f2ee9,     jurusan: 'ipa',     matapelajaran: 'fisika',     soal: 'agega',     jawabana: 'hjkbkjb',     jawabanb: 'kjbkjb',     jawabanc: 'kjbkjb',     jawaband: 'kjbkjb',     jawabane: 'kjbkbkj',     kuncijawaban: 'kjbk',     __v: 0  } 

you can perform single request match list of _id $in :

var b = det.map(function(h) {      soal.find("_id": {         $in: h.id_soal     }, function(err, solarray) {         if (err) {             console.log(err);         } else {             res.render('ujian/viewdetail', {                 ujian: iduji,                 detail: det,                 soal: solarray,                 title: 'lihat form ujian'             });         }     }); }); 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -