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

128
Views
Async Await dentro del bucle?

Estoy luchando con esto. Tengo en mi perfil de base de datos {nombre: cadena, tabla: 0}, y estoy usando un ciclo for para asignar el número de la tabla a los diferentes usuarios, pero esto no funciona. El ciclo for funciona bien si revisé en la consola, pero en la solicitud del cartero, no funciona.

Cuando filtro por número de tabla de la base de datos, hay más de 5 resultados por tabla. Y en algunos casos, hay irregularidades, como tabla 1: 8 usuarios, tabla 2: 5 usuarios, etc.

 const ProfileSchema = new Schema( { name: { type: String, required: true, }, password: { type: String, required: true, }, moderator: { type: Boolean, default: false, }, email: { type: String, required: true, }, country: { type: String, required: true, }, institution: { type: String, /* required: true */ }, score: { type: [Number], default: [], }, active: { type: Boolean, required: true, default: false, }, img: String, meetLink: String, table: { type: Number, default: 0, }, group: Number, },

rutas/index.js

 router.put('/asignTable', async (req, res) => { let users = await Profile.find() shuffle(users) asignTable(users) res.send(users)

rutas/utils.js

 async function asignTable(users) { var contador = 0 let numTable = 1 filter = {} for (const user of users) { const filter = { name: user.name } const update = { table: numTable } if (contador == 5) { contador = 0 numTable++ console.log(`desde el if ${contador}`) } else if (contador < 5) { await Profile.findOneAndUpdate(filter, update).then(contador++) console.log(`desde el elseif contador:${contador} numtable:${numTable}`) } } } })
about 4 years ago · Juan Pablo Isaza
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!