在windows终端下Mongod运行正常,但Nodemon显示以下错误:
C:\Users\enzoc\desktop\api\node_modules\mongoose\lib\index.js:520
throw new mongoose.Error.MissingSchemaError(name);
^
MissingSchemaError: Schema hasn't been registered for model "Usuario".
Use mongoose.model(name, schema)
at Mongoose.model (C:\Users\enzoc\desktop\api\node_modules\mongoose\lib\index.js:520:13)
at Object.<anonymous> (C:\Users\enzoc\desktop\api\controllers\UsuarioController.js:2:26)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\enzoc\desktop\api\routes\api\v1\usuario.js:3:27)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:973:32)
at Function.Module._load (node:internal/modules/cjs/loader:813:14)
at Module.require (node:internal/modules/cjs/loader:997:19)
at require (node:internal/modules/cjs/helpers:92:18)
at Object.<anonymous> (C:\Users\enzoc\desktop\api\routes\api\v1\index.js:3:25)
[nodemon] app crashed - waiting for file changes before starting...在这里,我将放置一些给出错误1的文件的图片:https://imgur.com/AJWDAB6
2:https://imgur.com/phyVz5I 3:https://imgur.com/EzBhb0E 4:https://imgur.com/9ogDG0p
发布于 2021-01-20 14:06:01
您尚未为usario定义架构,或者尚未将其导入以在.model()函数中使用。你可以尝试类似这样的东西
const Usario = mongoose.model('User', new Schema({ name: String }));有关更多示例和函数文档,请访问https://mongoosejs.com/docs/api/model.html#model_Model或https://mongoosejs.com/docs/api/schema.html#schema_Schema
发布于 2021-01-20 14:12:47
每当我们遇到这类问题时,一定要记得检查堆栈跟踪!
> at Object.<anonymous>
> (C:\Users\enzoc\desktop\api\controllers\UsuarioController.js:2:26)如果您检查此行,您将了解到在第2行中,Usuario模型/模式已被初始化。但是在您的系统中没有具有te受尊重名称的文件。请创建该文件。
有关更多详细信息,请查看to create a mongoose schema。
希望你的问题得到解决!
https://stackoverflow.com/questions/65803710
复制相似问题