In my models/user.js
file:
var mongoose = require(\'mongoose\');
var Schema = mongoose.Schema;
var userSchema = new Schema({
(define schema
I literally research lot and I found a solution so, I share this solution to you so, no one can face that cheap mistake that I did.
Please remember, you just need to add the same name in ref
as you gave in your model
because its case sensitive ( Product !== product ).
const Product = new mongoose.model('Product', productSchema);
product: {
type: mongoose.Schema.ObjectId,
ref: 'Product', <-- Should be same as modelName
required: [true, 'Cart must belong to a product']
}