I am trying to display the extracted data from mongodb into ejs template in the table format. I have created 1 database by name test1 inside that i have created 1 collection by name person.
Person collection attributes are : name and surname.
My express.js code :
router.route('/bears')
// create a bear (accessed at POST http://localhost:8080/api/bears)
.get(function(req, res) {
var peopleList = [];
var title = "Users in Database:";
Bear.find(function(err, people) {
if (err)
res.send(err);
for(var i = 0; i < people.length; i++)
{
peopleList.push({name: people[i].name, surname: people[i].surname});
}
console.log(peopleList);
console.log(peopleList[0].name + ' ' + peopleList[0].surname);
res.render('disp', {peopleList: peopleList,title: title});
});
});
My disp.ejs code :
<div>
<table>
<tr>
<th>Name</th>
<th>SurName</th>
</tr>
<% for (var i = 0; i < peopleList.length; i++) { %>
<tr>
<td><%= peopleList[i].name %></td>
<td><%= peopleList[i].surname %></td>
</tr>
<% } %>
</table>
</div>
It is displaying the following output :OutPut
It is not displaying the surname. What is the problem?
`
via animesh123
No comments:
Post a Comment