【发布时间】:2021-11-20 13:36:47
【问题描述】:
我正在使用带有 typeorm 和 mongodb 的 nestjs 设置一个简单的 API。但是,当我发出一个简单的 http 请求时,会出现以下错误
[Nest] 8852 - 09/28/2021, 6:06:03 PM [ExceptionsHandler] Cannot read property 'prototype' of undefined +4874934ms TypeError: Cannot read property 'prototype' of undefined at FindCursor.cursor.toArray (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:669:37) at MongoEntityManager.<anonymous> (C:\Users\admin\Documents\projects\shoplist\api\node_modules\typeorm\entity-manager\MongoEntityManager.js:60:54) at step (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:143:27) at Object.next (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:124:57) at fulfilled (C:\Users\admin\Documents\projects\shoplist\api\node_modules\tslib\tslib.js:114:62) at processTicksAndRejections (internal/process/task_queues.js:95:5)
offices.controller.ts
@Get('/list')
findAll() {
return this.officesService.findAll();
}
offices.service.ts
async findAll() {
try {
const offices = await this.officesRepository.find();
return { success: true, message: 'Office successfully retrieved!', data: offices }
} catch(e) {
throw new InternalServerErrorException({ success: false, error: e.message })
}
}
老实说,我不知道为什么它会给我错误 500 的消息。知道发生了什么吗?
【问题讨论】:
-
你分享的sn-ps没问题。其中哪一行触发了该错误?
-
我不确定。我已更新问题以包含完整的堆栈跟踪
-
您使用的是 Mongo v4 吗?如果是这样,TypeORM 还不支持它
-
我使用的是 mongo v4.4.6。这很奇怪,因为一些 http 调用正在工作,我可以看到存储在我的数据库中的值