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

150
Visualizações
I'm using an array to update MYSQL database but the ID dosn't match

I'm looping through an array in node JS to update MYSQL database but the array starts at 0 and my auto incrementing database starts at 1. This obviusly offsets my whole data base by 1 row. Would much appreciate a solution to this. I'm using the sequelize NPM package aswell. Thanks in advance.

function ejsoutput(json){
  
  for(var i = 0; i < 10;i++){
    
    const updatedRank = json.entries[i].rank;
    const updatedRating = json.entries[i].rating;
    const updatedName = json.entries[i].character.name;
    const updatedRealm = json.entries[i].character.realm.slug;
    const updatedFaction = json.entries[i].faction.type;
    const updatedPlayed = json.entries[i].season_match_statistics.played;
    const updatedWon = json.entries[i].season_match_statistics.won;
    const updatedLost = json.entries[i].season_match_statistics.lost;

    Product.findByPk(i)
    .then(product => {
      product.rank = updatedRank;
      product.rating = updatedRating;
      product.name = updatedName;
      product.realm = updatedRealm;
      product.faction = updatedFaction;
      product.played = updatedPlayed;
      product.won = updatedWon;
      product.lost = updatedLost;
      return product.save();
    })
    .then(result => {
      console.log('UPDATED PRODUCT')
    })
    .catch(err => console.log(err));
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just added this to the code.

Product.findByPk(i + 1)
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