how do i update nested fields with mongoose?

Ok, so I managed to figure it out.

I’ll leave the answer if someone is interested

pollSchema.findOneAndUpdate(pollId: req.body.pollId, "sections.questions.questionIndex": req.body.questionIndex,{$set: {"sections.$[s].questions.$.value": req.body.value}},{arrayFilters: [{"s.sectionIndex": req.body.sectionIndex}]})

For more information go to:

$ operator


$[< identifier >]

I’d recommend to read these articles completely, but you’ll get the idea just with the sections on those hyperlinks

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top