title: TypeORM error with MongoDB: .find() does not work, error: TypeError: Cannot read property 'prototype' of undefined
body: <p>I set up a Nest.Js / TypeORM / MongoDB stack as described <a href="https://medium.com/@chnirt/how-do-i-practice-with-nestjs-nestjs-typeorm-mongodb-9e407818a296" rel="nofollow noreferrer">here</a>.</p>
  <p>It works to create an object user in MongoDB using the <code>create()</code> function, the object is recorded into the right database into the <code>User</code> collection.</p>
  <p>However, when I attempt to get it using the <code>find({id})</code> or the <code>findAll()</code> function I get an error and I cannot get the item from the database even though it's there.</p>
  <p>Here is my <code>user.service.ts</code> file:</p>
  <pre><code>import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
  import { InjectRepository } from '@nestjs/typeorm';
  import { MongoRepository } from 'typeorm';
  import { validate } from 'class-validator';
  import { CreateUserDto } from './user.dto';
  import { User } from '../model/user.entity';
  import { UserRO } from './user.interface';
  
  @Injectable()
  export class UserService {
    constructor(
      @InjectRepository(User)
      private readonly userRepository: MongoRepository&lt;User&gt;,
    ) {}
  
    // abstracting access to the model via service
    public async getAll() {
      // getting data from database
      return await this.userRepository.find();
    }
  
    // abstracting access to the model via service
    public async get(id: string) {
      const user = await this.userRepository.findOne({ _id: id });
      if (!user) {
        const errors = { User: ' not found' };
        throw new HttpException({ errors }, 401);
      }
  
      return this.buildUserRO(user);
    }
  
  
  
    async create(dto: CreateUserDto): Promise&lt;UserRO&gt; {
      // check uniqueness of username/email
      const { username } = dto;
      const newUser = new User();
      newUser.username = username;
      // newUser.contexts = [];
  
      const errors = await validate(newUser);
      if (errors.length &gt; 0) {
        const _errors = { username: 'Userinput is not valid.' };
        throw new HttpException(
          { message: 'Input data validation failed', _errors },
          HttpStatus.BAD_REQUEST,
        );
      } else {
        const savedUser = await this.userRepository.save(newUser);
        return this.buildUserRO(savedUser);
      }
    }
  
  
  }
  
  </code></pre>
  <p>and also the <code>user.interface.ts</code>:</p>
  <pre><code>export interface UserData {
    username: string;
    _id: string;
  }
  
  // user response object
  export interface UserRO {
    user: UserData;
  }
  </code></pre>
  <p>and a part of the <code>user.controller.ts</code>:</p>
  <pre><code>  @Get(':id')
    findOne(@Param('id') id: string): Promise&lt;UserRO&gt; {
      console.log(`getting user with id: ${id}`);
      const user = this.serv.get(id);
      return user;
    }
  </code></pre>
  <p>and finally the <code>model/user.entity.ts</code>:</p>
  <pre><code>@Entity({ name: 'User' })
  export class User {
    @ObjectIdColumn()
    _id: string;
  
    @Column({ type: 'varchar', length: 50 })
    username: string;
  
    @OneToMany((type) =&gt; Context, (context) =&gt; context.user)
    contexts: Context[];
  }
  </code></pre>
  <p>The error I get when I try to find the saved context:</p>
  <pre><code>[Nest] 75671  - 09/22/2021, 9:22:18 PM   ERROR [ExceptionsHandler] Cannot read property 'prototype' of undefined
  TypeError: Cannot read property 'prototype' of undefined
      at FindCursor.cursor.toArray (/Users/deemeetree/Documents/Root/benchmark-sql-graph/src/entity-manager/MongoEntityManager.ts:707:37)
      at MongoEntityManager.&lt;anonymous&gt; (/Users/deemeetree/Documents/Root/benchmark-sql-graph/src/entity-manager/MongoEntityManager.ts:190:46)
      at step (/Users/deemeetree/Documents/Root/benchmark-sql-graph/node_modules/typeorm/node_modules/tslib/tslib.js:143:27)
      at Object.next (/Users/deemeetree/Documents/Root/benchmark-sql-graph/node_modules/typeorm/node_modules/tslib/tslib.js:124:57)
      at fulfilled (/Users/deemeetree/Documents/Root/benchmark-sql-graph/node_modules/typeorm/node_modules/tslib/tslib.js:114:62)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
  </code></pre>
  <p>I tried with MongoDB 4. and 3. versions and it's the same problem.</p>
  <p>What am I doing wrong and how to get pass this error and be able to query the records well in MongoDB?</p>
  <p>Thanks!</p>