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

89
Views
Mongoose finding record in a nested json and then update the array field

I like to find a plan purchasedPlans.plan for a certain user(email) and then update its status to "Active"

const userSchema = new Schema({
    email: String ,    
    purchasedPlans:[{plan:String ,  status:String,}]
});

What is the code in Mongoose.

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

0

You can use positional operator $, like this:

User.updateOne({
  "email": "user_email",
  "purchasedPlans.plan": "plan_to_change_status"
},{
  "$set": {
    "purchasedPlans.$.status": "Active"
  }
})
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!