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"
我实际上已经将模型名称从user更改为exercise,然后我得到了这个错误:“throw new _mongoose.Error.OverwriteModelError(name); OverwriteModelError:Cannot overwrite Exercise model once compiled. [0]at new OverwriteModelError”
更多回答
This usually happens when you're trying to have multiple schema definitions with same name.
当您尝试使用相同名称的多个模式定义时,通常会发生这种情况。
优秀答案推荐
When using same model twice or more, code this way
当使用同一模型两次或更多时,可以这样编写代码
module.exports = mongoose.models['Users'] || mongoose.model('Users', userSchema)
Use this:
使用以下命令:
module.exports = mongoose.models['Users'] || mongoose.model('Users', userSchema)
Instead of:
不是:
module.exports = mongoose.model('Users', userSchema)
The model name in which you require in your js file should match the model name which you export from that other js file.
您在js文件中需要的模型名称应该与从其他js文件导出的模型名称相匹配。
The model file from which you export:
从中导出的模型文件:
->module.exports=mongoose.model('Exercise',exerciseSchema)
->mode.exports=mongoose.model(‘Exercise’,ExerciseSchema)
The model file in which you require the given model:
->var Exercise=require('./exerciseModel')
需要给定模型的模型文件:->var Exercise=Required(‘./ExerciseModel’)
If you try to use any other name for your model then it will try to overwrite the previous name provided by you, this will create the confusion to compiler and it will throw the model name overwrite error.
如果您尝试为您的模型使用任何其他名称,则它将尝试覆盖您提供的先前名称,这将对编译器造成混淆,并将抛出模型名称覆盖错误。
In my case the same was happened.
在我的情况下,也发生了同样的事情。
I hope it will help!!
我希望它能帮上忙!
更多回答
Hi, your code duplicates the previous answer
您好,您的代码重复了前面的答案
我是一名优秀的程序员,十分优秀!