Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

401
Visualizações
TypeORM and MongoDB and Repositories: Cannot read property 'prototype' of undefined

I'm trying implement TypeORM with MongoDB using repositories. However, when I try to make use of repositories to manage the database, using the same structure as in this repository, things go a bit sideways. I'm getting the following error:

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'prototype' of undefined

I have tried the following code:

import { Request, Response } from 'express';
import { getMongoRepository } from "typeorm";
import Task from "../models/Task";

export default class TasksController {
async listAll(request: Request, response: Response): Promise<Response> {
    const tasksRepository = getMongoRepository(Task);
    try {
      const tasks = await tasksRepository.find();
      return response.status(200).json({ "items": tasks });
    } catch (err) {
      return response.status(400).json({
        message: err.message,
      });
    }
  }
}

I know the error refers to implementing the .find() method. I have even managed to fetch the data, using a suggestion from this post replacing:

const tasks = await tasksRepository.find();

with

const tasks = await tasksRepository.createCursor(tasksRepository.find()).toArray();

but I still get the above mentioned error.

Anyone understands what's going on?

I have also managed to save data directly to the database through the use of the following script:

server.ts

import express from 'express';
import { createConnection } from 'typeorm'

const app = express();
const port = 3333;
createConnection();

app.use(express.json());

app.post('/tasks', (async (request, response) => {
  const { item } = request.body;
  task.item = item;

  const task = new Task();
  (await connection).mongoManager.save(task);

  return response.send(task);
}))

app.listen(port, () =>
  console.log(`Server running on port ${port}`)
);
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

TypeORM is not support mongodb v4. https://github.com/nestjs/nest/issues/7798

You can use 3.7.0 instead.

over 4 years ago · Santiago Trujillo Relatório

0

I submitted a pull requests to resolve this. https://github.com/typeorm/typeorm/pull/8412 if anyone is looking for a workaround in the meantime.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda