Last active
October 18, 2018 08:32
-
-
Save fatihturan/e4a301ec69383dfbd36786f9b9b9541b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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