0

I am new in MEAN stack development. I am developing a simple e-shopping application using node and mongoodb with angular. When I start application, I get the following error:

MissingSchemaError: Schema hasn't been registered for model "Review". Use mongoose.model(name, schema)

Here is my code.

review.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const ReviewSchema = new Schema({
    owner: { type: Schema.Types.ObjectId, ref: 'User' },
    title: String,
    description: String,
    rating: { type: Number, default: 0 },
    created: { type: Date, default: Date.now }
});

module.exports = mongoose.model('Review', ReviewSchema);

product.js

const mongoose = require("mongoose");
const deepPopulate = require("mongoose-deep-populate")(mongoose);
const Schema = mongoose.Schema;
const mongooseAlgolia = require("mongoose-algolia");

const ProductSchema = new Schema({
  category: { type: Schema.Types.ObjectId, ref: "Category" },
  owner: { type: Schema.Types.ObjectId, ref: "User" },
  reviews: [{ type: Schema.Types.ObjectId, ref: "Review" }],
  image: String,
  title: String,
  description: String,
  price: Number,
  created: { type: Date, default: Date.now }
});

module.exports = mongoose.model("Product", ProductSchema);

config.js

module.exports = {
    database :'mongodb://localhost:27017/dabdatabase',
    port: process.env.PORT || 3000,
    secret: 'ganesh123'
};

Please help me.

Community
  • 1
  • 1
Ganesh Kumar
  • 99
  • 4
  • 11
  • 1
    Where did you use `Product` and `Review` schema's??? Most probably issue is with the order of importing the schema's. – Ashh Jan 07 '20 at 06:36
  • Yes its order of importing the schema's issue.when set proper order of importing schema's its working. Thank you @Ashh – Ganesh Kumar Jan 08 '20 at 18:45

0 Answers0