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

205
Visualizações
Function doesn't not change variable - NodeJs

I'm building a nodejs app using mongoose. I am trying to change a variable that is outside the mongoose findOne function, but, for some reason, it doesnt change that var.

    let existent_teams;

    match.findOne({ match_id: match_id }, (err, docs) => {
        if(err) console.error(err);

        var length = docs.match_teams.length; //Returns 0

        existent_teams = length; //Giving existent_teams var the length value
    });

    console.log(existent_teams); //Returns undefined

And it is returning me that the value of the variable existent_teams is undefined... I already tried changing the let to const and also to var

about 4 years ago · Juan Pablo Isaza
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