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

149
Vistas
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 Respuestas
Responde la pregunta

0

I just added this to the code.

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