Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mongoose = require('mongoose');
- let Schema = mongoose.Schema;
- let BookSchema = new Schema(
- {
- title: {type: String,required: true},
- author: {type: Schema.ObjectId,ref:'Author',required: true},
- summary: {type: String, required:true},
- isbn: {type: String, required:true},
- genre: [{type: Schema.ObjectId, ref:'Genre'}]
- }
- );
- BookSchema
- .pre('countDocuments');
- BookSchema
- .virtual('url')
- .get(function () {
- return '/catalog/book/'+this._id;
- });
- module.exports = mongoose.model('Book',BookSchema);
- 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);
- }
- },
- function (err,results) {
- res.render('index',{title: 'Local Library Home',error:err, data:results});
- res.json({data: results});
- });
- res.send('NOT IMPLEMENTED: Site Home Page');
- };
Add Comment
Please, Sign In to add comment