932 viewsMern Amazona

OverwriteModelError: Cannot overwrite `user` model once compiled.
at Mongoose.model (C:\Users\HP\Desktop\amazona\backend\node_modules\mongoose\lib\index.js:554:13)
at file:///C:/Users/HP/Desktop/amazona/backend/models/userModel.js:15:23

Bassir Changed status to publish November 26, 2023

you might get this error if you use the same model in different files but your require path has an other case.

For example, in my situation I had require('./models/User') in one file, and then in another file where I needed access to the User model, I had require('./models/user').

I guess the lookup for modules & mongoose is treating it as a different file. Once I made sure the case matched in both it was no longer an issue.

Bassir Answered question October 11, 2022