var author = new Author(authordetail);
^
TypeError: Author is not a constructor
at authorCreate (C:\Users\smook\Desktop\NewProject\express-library\populatedb.js:38:16)
at C:\Users\smook\Desktop\NewProject\express-library\populatedb.js:112:11
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:3866:24
at eachOfArrayLike (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:1055:9)
at eachOf (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:1103:5)
at _parallel (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:3865:5)
at Object.parallelLimit [as parallel] (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:3948:5)
at createGenreAuthors (C:\Users\smook\Desktop\NewProject\express-library\populatedb.js:110:11)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:3866:24
at replenish (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:998:17)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:1002:9
at eachOfLimit (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:1027:24)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:1032:16
at _parallel (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:3865:5)
at Object.series (C:\Users\smook\Desktop\NewProject\express-library\node_modules\async\dist\async.js:4721:5)
at Object.<anonymous> (C:\Users\smook\Desktop\NewProject\express-library\populatedb.js:212:7)
i think this is and an error in the populatedb.js file.
TypeError: Book.find is not a function
at exports.book_list (C:\Users\smook\Desktop\NewProject\express-library\controllers\bookController.js:34:10)
at Layer.handle [as handle_request] (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\layer.js:95:5)
at next (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\layer.js:95:5)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:281:22
at Function.process_params (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:275:10)
at Function.handle (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:174:3)
at router (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:317:13)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:335:12)
at next (C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:275:10)
at C:\Users\smook\Desktop\NewProject\express-library\node_modules\express\lib\router\index.js:635:15
same thing happen with the .find() method.
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.count(callback);
},
book_instance_count: function(callback) {
BookInstance.count(callback);
},
book_instance_available_count: function(callback) {
BookInstance.count({status:'Available'},callback);
},
author_count: function(callback) {
Author.count(callback);
},
genre_count: function(callback) {
Genre.count(callback);
},
}, function(err, results) {
res.render('index', { title: 'Local Library Home', error: err, data: results });
console.log(err);
});
};
// Display list of all books.
exports.book_list = function(req, res, next) {
Book.find({}, 'title author ')
.populate('author')
.exec(function (err, list_books) {
if (err) { return next(err); }
// Successful, so render
res.render('book_list', { title: 'Book List', book_list: list_books});
});
var mongoose = require('mongoose')
var Schema = mongoose.Schema;
var 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'}]
})
//Virtual for book's url
BookSchema
.virtual('url')
.get(function (){
return '/catalog/book/' + this._id
})
module.export = mongoose.model('Book', BookSchema)
I am in love with this tutorial but this error stop my learning.
And, excuse my english, please.
Thanks for read.