Currently, I am experimenting with using mongoose, mongoDB, next, and express in a test project. Despite referencing solutions like Cannot overwrite model once compiled Mongoose and others, I am encountering issues unique to my situation.
Upon initialization, an error "User.find is not a function" is displayed, followed by the error "Cannot overwrite users
model once compiled" after reloading the server (e.g., saving changes).
The versions I am working with include nvm 10.18.0, next 9.3.4, express 4.17.1, mongoose 5.9.7
Below are snippets from my files:
//server.js
const express = require('express');
const next = require('next');
//...omitted for brevity
module.exports = User;
//./models/user.js
var mongoose = require('mongoose');
//...omitted for brevity
const User = mongoose.model('users', SomeModelSchema );
module.exports = User;
//./pages/index.js
const User = require('../models/user');
//...omitted for brevity
export default Home
If anyone has suggestions on how to resolve these errors, I would greatly appreciate it.