2

I'm setting up a simple API using nestjs with typeorm and mongodb. However when I make a simple http request I get the following error

[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 })
  }
}

I honestly don't know why it gives me error 500 with that message. Any idea what's happening?

4
  • the snippets that you shared are fine. Which line of them triggers that error? Commented Sep 28, 2021 at 15:05
  • I'm not sure. I've updated the question to include full stack trace Commented Sep 28, 2021 at 15:06
  • Are you using Mongo v4? If so, TypeORM doesn;t support it yet Commented Sep 28, 2021 at 15:08
  • I'm using mongo v4.4.6. It's strange because some of the http calls are working and I can see the values stored in my DB Commented Sep 28, 2021 at 15:10

2 Answers 2

1

These errors seam like a mongodb version problem. If you are using mongodb > 3, Typeorm doesn't support yet. They have PR open at github --> https://github.com/typeorm/typeorm/issues/7907

Sign up to request clarification or add additional context in comments.

Comments

1

It's issue of mongodb version with typeorm.

typeorm doesn't have support for >3 version yet.

Run this to resolve issue.

mongodb@3 @types/mongodb@3

Complete dependencies

npm install typeorm @nestjs/typeorm mongodb@3 @types/mongodb@3

Resolved same issue following this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.