0

i had actually changed the model name from user to exercise and then i get this error: " throw new _mongoose.Error.OverwriteModelError(name); OverwriteModelError: Cannot overwrite Exercise model once compiled. [0] at new OverwriteModelError"

Ahmed Boutaraa
  • 1,908
  • 1
  • 12
  • 10
  • Does this answer your question? [Cannot overwrite model once compiled Mongoose](https://stackoverflow.com/questions/19051041/cannot-overwrite-model-once-compiled-mongoose) – Black Mamba Dec 29 '19 at 17:07
  • This usually happens when you're trying to have multiple schema definitions with same name. – Black Mamba Dec 29 '19 at 17:08

2 Answers2

0

When using same model twice or more, code this way

module.exports = mongoose.models['Users'] || mongoose.model('Users', userSchema)
GMKHussain
  • 3,342
  • 1
  • 21
  • 19
0

Use this:

module.exports = mongoose.models['Users'] || mongoose.model('Users', userSchema)

Instead of:

module.exports = mongoose.model('Users', userSchema)
Tyler2P
  • 2,324
  • 26
  • 22
  • 31