Created
December 7, 2022 18:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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