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

182
Views
In the browser showing empty while fetching data from mongodb and send to my getdata.ejs file

My index.js file get method

app.get('/getdata', function(req, res){
  var resultArray = [];
  mongo.connect(url, function(err, db){
    assert.equal(null, err);
    var cursor = db.collection('satyamsoft').find();
    cursor.forEach(function(doc, err){
      assert.equal(null, err);
      resultArray.push(doc);
      console.log(resultArray);
    });

  });

  res.render('pages/getdata', {holedata: resultArray});
});

My getdata.ejs file

<h2> Family Details </h2>
<ul>
    <% holedata.forEach(function(data) { %>
        <li><%= data.name %> - <%= data.title %> - <%= data.age %></li>
    <% }); %>
</ul>

After executing the get method in the console showing data which is fetch from mongodbColnose data

But in the web page showing empty enter image description here

Am i doing anything wrong. Please help me. Advance thanks.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This might help on client side in your .ejs file -

<script>
  var holedata = <%- JSON.stringify(holedata) %>;
</script>
about 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!