I am trying to display articles stored in my blogs collection using mongoose in ejs page. But got stuck due to following error.
blogs.js -
var mongoose = require('mongoose');
var blogSchema = mongoose.Schema({
title : String,
description : String,
time : { type : Date, default: Date.now },
details : String
});
module.exports = mongoose.model('blogs',blogSchema);
routes.js
app.get('/blogs',function(req, res) {
//blogs.find();
blogs.find({})
.sort({'date': -1})
.exec(function(err, events) {
if (err)
res.send(err);
res.render('blogs.ejs', {
blogs : blogs
});
});
blogs.ejs
<div class="grid" id="lvc-past-blogs-container">
<div class="col-1-1">
<div id="past-speakers">
<h2><i>-PAST SPEAKERS</i></h2>
<% for (var i = 1; i < blogs.length; i++) { %>
<ul>
<li><a href="<%= blogs[i].title %>"><%= blogs[i].description %></a> (<%= blogs[i].time %> | <%= blogs[i].details %>)</li>
</ul>
<% }; %>
</div>
</div>
</div>
error
via pallavi vetal
No comments:
Post a Comment