skip to Main Content

Mongodb – NodeJS (express) – Javascript promise is being executed whether success or failure, How can I make a promise for each case?

exports.postDeleteProduct = (req, res, next) => { const userId = req.body.userId; User.deleteOne({ _id: userId, userId: req.session.userAuth._id }) .then(() => { console.log("DESTROYED PRODUCT"); //process reaching here whether the above deleteOne happens or not res.redirect("/users"); }) .catch((err) => console.log(err)); }; Also, the…

VIEW QUESTION

Mongodb sum of views by day name

I have this simple collection of views: Views: [ { title: "cartoons", views: 1, created_at: 2022-10-03 12:00:00.000Z }, { title: "songs", views: 4, created_at: 2022-10-04 12:00:00.000Z }, { title: "lectures", views: 3, created_at: 2022-10-10 12:00:00.000Z }, { title: "news", views:…

VIEW QUESTION
Back To Top
Search