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

116
Views
I m trying to change to field with $set in mongoose but only one field change?
Packages.findOneAndUpdate(
{filter},
{$set:{$inc:{reviews:1}},
       rating:4},
{new:true,
 upsert:true,
 multi:true}, 
 function(err, found){
     if(!err){
       console.log("updated")
     }else{
       console.log(err)
     }
   })

Only rating is getting changed and reviews is not incremented at all. Both reviews and rating is of same type i.e Number.

And I'm getting "updated" message in console.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Apply $inc without $set:

Packages.findOneAndUpdate({filter}, {
  $set: { rating: 4 },
  $inc: { reviews: 1 }
}, {
  new: true,
  upsert: true,
  multi: true
});

Working example

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!