I am using angular-fullstack generator and I have added a Model person. When I try to require the person model in the seed.js file I get this error.
/Users/dev/wishlist/node_modules/mongoose/lib/index.js:334
throw new mongoose.Error.OverwriteModelError(name);
^
OverwriteModelError: Cannot overwrite `Person` model once compiled.
at Mongoose.model (/Users/dev/wishlist/node_modules/mongoose/lib/index.js:334:13)
at Object.<anonymous> (/Users/dev/wishlist/server/api/wishList/person.model.js:11:27)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/dev/wishlist/server/api/wishList/wishList.controller.js:4:14)
at Module._compile (module.js:456:26)
I followed the same structure used for the "Thing" model that comes with the generator. Also did a search and where Person is in the code base and its only in the person.model.js and in the controller.
person.model.js:
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var PersonSchema = new Schema({
name: String,
quote: String
});
module.exports = mongoose.model('Person', PersonSchema);
wishlist.controller.js:
'use strict';
var _ = require('lodash');
var Person = require('./person.model');
// Get all the People that have wish lists
exports.getPeople = function(req, res) {
Person.find(function (err, people) {
if(err) { return handleError(res, err); }
return res.json(200, people);
});
};
function handleError(res, err) {
return res.send(500, err);
}
What am I missing?