'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
Solution 1:[1]
Replace
<% file.forEach((docs) => { %>
With
<% for (let docs of file) { %>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ibrahim |
