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

90
Visualizações
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 Respostas
Responde à pergunta

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 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