Skip to content

Instantly share code, notes, and snippets.

@kazi331
Created December 7, 2022 18:19
Show Gist options
  • Save kazi331/e65379eac7178afbafee692104ceb963 to your computer and use it in GitHub Desktop.
Save kazi331/e65379eac7178afbafee692104ceb963 to your computer and use it in GitHub Desktop.
Cannot overwrite `Sector` model once compiled. - mongoose override model once compiled error fixed.
import mongoose from "mongoose";
const appointmentSchema = new mongoose.Schema({
agree: Boolean,
name: String,
sectors: [
{
key: String,
label: String,
value: String,
}
]
})
// const Appointment = mongoose.model('Appointment', appointmentSchema); // contains override errors
const Appointment = mongoose.models.Appointment || mongoose.model('Appointment', appointmentSchema); // fixed
export default Appointment;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment