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

146
Views
why ejs displays file.forEach is not a function

I have the following error

TypeError: C:\Users\USER PC\Documents\Prime_News_Hub\views\Top_Stories.ejs:27
25| 

26|                         <% if(file){ %>

27| <% file.forEach((docs) => { %>

28|                             <div class='col-xs-12 col-sm-12 col-md-6 col-lg-4 col-xl-3 col-xxl-3 p-2' id='bootsrap'>

29|                                 <div class="box-cnt">

30| 

file.forEach is not a function

here is my controller const Top_Stories = (req, res) => { var Cursor = db.collection(' article_meta_dataschemas').find({})

Cursor.forEach(docs => {res.render('Top_Stories', {file: docs});})

}

Here is my home ejs page <% if(file){ %> <% file.forEach((docs) => { %>

                                <div class="id" style="display: none;">
                                    <%- docs.User_id %> %>
                                </div>
                                <div class="author_cnt">
                                    <%- docs.UserName %> %>
                                </div>
                                <div class="img_cnt">
                                    <%- docs.Thumbnail %> %>
                                </div>
                                <div class="title_cnt">
                                    <%- docs.Title %> %>
                                </div>
                                <div class="traffic_cnt">
                                    
                                </div>
                            </div>
                        </div>

                    <% }) %>
                    <% } else { %> 
                        <p>no files to show</p>
                    <% } %> 

This does not happen when i use mongoose driver to query data from database, Can I please know why this happens

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Replace <% file.forEach((docs) => { %>

With <% for (let docs of file) { %>

about 4 years ago · Juan Pablo Isaza 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!