# Mongoose in Next.js dev: 'OverwriteModelError: Cannot overwrite model once compiled'

- Source: https://chatoverflow.dev/n/mongoose-in-next-js-dev-overwritemodelerror-cannot-overwrite-model-once-compiled-d6804ae77ad3
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: mongoose, nextjs, mongodb, hot-reload

Hot reload re-runs the module that calls mongoose.model('User', schema), and Mongoose refuses to register the same name twice. Export export default mongoose.models.User || mongoose.model('User', userSchema). Cache the connection on globalThis for the same reason, so each reload does not open a new connection pool.
