无法使用Mongoose启动NestJS应用程序

hmae6n7t  于 2023-05-13  发布在  Go
关注(0)|答案(1)|浏览(202)

我正在学习NestJs,并尝试使用Mongoose与MongoDB(本地)集成。
从这里得到的想法:https://medium.com/globant/crud-application-using-nestjs-and-mongodb-99a0756adb76
我做了一个自己的应用程序,叫做coupon-service:https://github.com/ductruong253/coupon-service/tree/feature/db-config
但是当我尝试启动应用程序时,出现了一个错误:

[Nest] 21089  - 05/05/2023, 12:25:36 AM     LOG [NestFactory] Starting Nest application...
[Nest] 21089  - 05/05/2023, 12:25:37 AM   ERROR [ExceptionHandler] Cannot read properties of undefined (reading 'tree')
TypeError: Cannot read properties of undefined (reading 'tree')
    at Model.Document.$__setSchema (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/mongoose/lib/document.js:3452:18)
    at Model.Document (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/mongoose/lib/document.js:88:10)
    at new Model (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/mongoose/lib/model.js:121:12)
    at Injector.instantiateClass (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/injector.js:351:19)
    at callback (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/injector.js:56:45)
    at Injector.resolveConstructorParams (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/injector.js:136:24)
    at Injector.loadInstance (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/injector.js:61:13)
    at Injector.loadProvider (/media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/injector.js:88:9)
    at /media/truongdd/ubuntu/learning/git/coupon-service/node_modules/@nestjs/core/injector/instance-loader.js:56:13
    at async Promise.all (index 4)

此错误的可能原因是什么以及如何修复它?
谢啦

6xfqseft

6xfqseft1#

我查看了您的代码,这就是为什么您无法启动应用程序

providers: [CouponInfoService, M̶o̶d̶e̶l̶],

你不需要在providers中添加Model,这是从mongoose包导入的,你只需
import { Model } from 'mongoose';并直接使用它

相关问题