Im working on a react/nextjs project and im using models/schemas from mongoose to connect to a mongoDB, but when the code change and next compile the changes, I get the error on my models.
OverwriteModelError: Cannot overwrite StoryList model once compiled.
thats my code:
import mongoose from "mongoose";
const StorySchema = new mongoose.Schema({
user: {
type: String,
require: true,
},
title: {
type: String,
},
text: {
type: String,
},
createdAt: {
type: Date,
default: Date.now(),
},
published: {
type: Boolean,
default: false,
},
});
module.export = mongoose.model("Story", StorySchema);
when i use this to export i get another error.
module.export = mongoose.models.Story || mongoose.model("Story", StorySchema);
Cannot read properties of undefined (reading 'Story')