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

282
Vistas
MongoDB update array with for loop index

I want to update an array document in a movie collection of mongoDB. However i can't pass the index i of the for loop as the property to update. e.g. it works when i update with "review.0.rating" but it doesn't if i update with review.i.rating. Any ideas??

DB collection

for (var i=0; i< movie[0].review.length; i++){
            //if the user made rating before, update his rating
            if(movie[0].review[i].user === req.body.userID ){  
              await db.collection('movies').updateOne(
                {_id:ObjectId(req.body.movieID)},
                {$set: {review.i.rating: idx} }
              );
              
            }
            
          }
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Can you try this: review[`${i}`].rating

about 4 years ago · Santiago Trujillo 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