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
mongoose query to update a document in a model
jsn = {
"data":[
 "Id":"123",
 "qnty":[{"qId":"3","qItem":123},]
]
}

hi, i want to update document's using mongoose in nodejs, but unable to do so, what i want is to update the "qitem" of qnty array of object and insert similar other objects in update, my approach is below.

var doc = await model.findOne({"data.Id":x});

//if i have qnty object already present i want to update its value
doc.toObject().data[0].qnty[0].qItem = 100;

//i want to push many object this is just example
doc.toObject().data[0].qnty.push({"qId":"4","qItem":124});

doc.save();
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you should use

model.update({"data.Id":x},{"data.qnty":doc.data[0]})

in place of doc.save() i think that will do the trick

over 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!