Probably this issue arose due to mongoose compatibility. I am working on an existing app. Today, all of sudden this issue started to appear when I tried to restart the app but it failed for the following error
Cannot set default value of path stats to a mongoose Schema instance
The stack trace took me to line number 47 of my User model. The line said.
stats: { type: UserStatsSchema, default: UserStatsSchema },
Right above the new Schema() call in user.js modal file, UserStatsSchema is defined
const UserStatsSchema = new Schema({
numLikes: { type: Number, default: 0 },
numPosts: { type: Number, default: 0 }
}, {_id: false});
I tried to figure out by searching over the internet. Since I am new to mongoose and it's Schema typecasting I am not sure what do I need to fix this issue.