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

175
Views
how to use data to update something with findOneAndUpdate()

I'm looking to update something in my DB, but I need to use data in the object in the DB.

Here is what I would like to do :

score.findOneAndUpdate({name: "global"}, {$set:{score: score+1}})

and here is what it looks like in DB :

{
  name: "global"
  score: 1
}

So I need to find global, and increment the score by one and update it to obtain

{
 name: "global"
 score: 2
}

I know that I could first, find and store the data, and after an update, but how can I do it once with findAndUpdate()?

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

0

You could instead use the $inc operator to increment the score field:

score.findOneAndUpdate({ name: "global" }, { $inc: { score: 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!