Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
Node.js render json map from mongodb

I want to show data from json map to express

this my code

var b = det.map(function(h) {
    var soalid = h.id_soal;
    var idarray = [ ];
    for (var i = 0; i < 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 to console I get data from json but not showing on express (web).

and I have this 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 
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can perform a single request to match a list of _id with $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'
            });
        }
    });
});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!