help with updating records in mongodb using express-router and mongoose.

59 views
Skip to first unread message

David Cotto

unread,
Mar 3, 2020, 7:14:44 AM3/3/20
to mongodb-user

Hello i have been stuck for days with this one problem..
i do not know how to go about my problem.

i basically want to update mongodb first by finding the projectId,
and then updating bannerData for each projectId found.

my mongodb records:

Below is my mongoose/express-router path. 
i feel like i am close but if i put in req.body.bannerData i get undefined...how do i update properly?

router.route('/saveAll/:projectId')
.put((req,res) => {
Banner.updateMany ({ projectId: req.params.projectId }, {
$set: { "bannerData.$[]": req.body}
},
function(err, response) {
if (err) {
res.send(err);
console.log(err);
console.log(req.body);
} else {
console.log(req.params.projectId);
console.log(response);
console.log(req.body);
}
})
});





Below is a bannerData that i wish to push to mongodb






Reply all
Reply to author
Forward
0 new messages