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.