Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
Cannot read property 'insertOnMatch' of undefined - TypeScript

I'm using TypeScript to create a match/player module in mongoose. I create this insertOnMatch function to use the mongoose findOneAndUpdate function adding the player to my match schema, but I'm recieving a UnhandledPromiseRejectionWarning while trying to update that document in mongo

Full error code:

(node:508) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'insertOnMatch' of undefined

insertOnMatch function

  private async insertOnMatch (matchId: String, playerId: String): Promise<void> {
    await Match.findOneAndUpdate({ matchId: matchId }, { $push: { matchPlayers: { playerId: playerId, playerRefererMatchId: matchId } } })
  }

create function

public async create (req: Request, res: Response): Promise<Response> {
    const newPlayerConfig = {
      playerId: generatedPlayerId,
      playerMatchRefererId: req.params.matchId
    }

    const newPlayer = await Player.create(newPlayerConfig)

    this.insertOnMatch(newPlayer.playerMatchRefererId, newPlayer.playerId).catch(err => { console.error(err) })

    return res.json(newPlayer)
  }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As I understand you try to call insertOnMatch on a functional component using this. And it is undefined as there's no class instance. accessing the 'this' keyword in a react functional component

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda