Thanks very much. NextJS seemingly rebuilds my User model at each page call, so this line saved me a persistent overwrite warning error:
mongoose.models = {};
You are welcome.
import mongoose from 'mongoose'; import { BookDocument } from './book.interface'; import { BookSchema } from './book.schema'; export const BookModel = mongoose.models.Book || mongoose.model<BookDocument>('Book', BookSchema); export default BookModel;
I think this is a better way.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks very much. NextJS seemingly rebuilds my User model at each page call, so this line saved me a persistent overwrite warning error:
mongoose.models = {};
You are welcome.
I think this is a better way.