Skip to content

Instantly share code, notes, and snippets.

@fatihturan
Created October 16, 2018 12:13
Show Gist options
  • Save fatihturan/5d65c4c8e9f9068508d8711fb0858d22 to your computer and use it in GitHub Desktop.
Save fatihturan/5d65c4c8e9f9068508d8711fb0858d22 to your computer and use it in GitHub Desktop.
var Book = require('../models/book');
var Author = require('../models/author');
var Genre = require('../models/genre');
var BookInstance = require('../models/bookinstance');
var async = require('async');
exports.index = function(req, res) {
async.parallel({
book_count: function(callback) {
Book.countDocuments({}, callback); // Pass an empty object as match condition to find all documents of this collection
},
book_instance_count: function(callback) {
BookInstance.countDocuments({}, callback);
},
book_instance_available_count: function(callback) {
BookInstance.countDocuments({status:'Available'}, callback);
},
author_count: function(callback) {
Author.countDocuments({}, callback);
},
genre_count: function(callback) {
Genre.countDocuments({}, callback);
}
}, function(err, results) {
res.render('index', { title: 'Local Library Home', error: err, data: results });
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment