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

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

0

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

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