schema hasnt been registred for model (MEAN STACK)

I'm learning the mean stack and when I try to start the server using

npm start

I get an exception saying that:

      throw new mongoose.Error.MissingSchemaError(name);
MissingSchemaError: Schema hasn't been registered for model "Firms".

here is my code Firms.js

   var mongoose = require('mongoose');
var CommentSchema = new mongoose.Schema({
  body: String,
  author: String,
  upvotes: {type: Number, default: 0},
  post: { type: mongoose.Schema.Types.ObjectId, ref: 'Post' }

CommentSchema.methods.upvote = function(cb) {
  this.upvotes += 1;;

CommentSchema.methods.downvote = function(cb) {
  this.upvotes -= 1;;

mongoose.model('Firms', CommentSchema);

as I can see the schema should be registered for the model 'Firms', but what can be possibly causing the exception to be thrown?

here's the app.js code with the mongoose initialization:

   var mongoose = require('mongoose');
var express = require('express');
var router = express.Router();
var passport = require('passport');
var jwt = require('express-jwt');

var Post = mongoose.model('Post');
var Comment = mongoose.model('Comment');
var Firm = mongoose.model('Firms');
var User = mongoose.model('User');

//var Crime = mongoose.model('Crime');

var auth = jwt({secret: 'SECRET', userProperty: 'payload'});

/* GET home page. */
router.get('/', function(req, res) {



Try using module.exports = mongoose.model('Firms', CommentSchema); also in your app.js try var Firms = require('Firms');


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.