Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
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 answers
Answer question

0

I just added this to the code.

Product.findByPk(i + 1)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!