`.find()` throws error while using mongodb
krissh-the-dev opened this issue · comments
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
While using MongoDB, repository.find()
method throws the following error:
[Nest] 15017 - 08/30/2021, 5:32:47 PM ERROR [ExceptionsHandler] Cannot read property 'prototype' of undefined
TypeError: Cannot read property 'prototype' of undefined
at FindCursor.cursor.toArray (/home/krish/github/nest-garbage/src/entity-manager/MongoEntityManager.ts:707:37)
at MongoEntityManager.<anonymous> (/home/krish/github/nest-garbage/src/entity-manager/MongoEntityManager.ts:97:23)
at step (/home/krish/github/nest-garbage/node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
at Object.next (/home/krish/github/nest-garbage/node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
at fulfilled (/home/krish/github/nest-garbage/node_modules/typeorm/node_modules/tslib/tslib.js:114:62)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I suppose this issue is there in TypeORM itself. But after searching for a while, I found a workaround on StackOverflow:
this.userRepository.createCursor(this.userRepository.find()).toArray();
But the injected repository does not appear to have a createCursor
method.
Btw, create()
and save()
methods works fine and just as expected.
Note:
This abnormal behaviour is not encountered while using Postgres.
Expected behavior
It should find and return all the documents(rows) in the collection(table) as an array.
Minimal reproduction of the problem with instructions
This is the repo I'm actually working on, I'm only learning NestJs, so it's already bare minimal.
https://github.com/KrishnaMoorthy12/nest-garbage
What is the motivation / use case for changing the behavior?
I think it's a bug (it obviously is), and it needs to be fixed (Please).
Environment
Nest version: 8.1.1
TypeORM version: 0.2.37
MongoDB driver: 4.1.1
For Tooling issues:
- MongoDB: 4.4.6
- Node version: 16.7.0
- Platform: Linux
Others:
Package manager: Yarn
Update:
I'm able to obtain the expected behaviour by downgrading MongoDB driver to v3.6.11
(the version used in the sample repository).
This isn't a bug + it's unrelated to this package. Please, report this issue in the appropriate repository (typeorm/typeorm).