Created
October 16, 2018 12:13
-
-
Save fatihturan/5d65c4c8e9f9068508d8711fb0858d22 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