Code sample - how all blog posts were queried
// from web.js
// main page - display all blog posts
// More Mongoose query information here
// http://mongoosejs.com/docs/finding-documents.html
app.get('/', function(request, response) {
// build the query
var query = BlogPost.find({});
query.sort('date',-1); //sort by date in descending order
// run the query and display blog_main.html template if successful
query.exec({}, function(err, allPosts){
// prepare template data
templateData = {
posts : allPosts
};
// render the card_form template with the data above
response.render('blog_main.html', templateData);
});
});
// end of main page