skip to Main Content

Mongodb – Cannot close mongoose connection

const mongoose = require("mongoose"); mongoose.connect("mongodb://localhost:27017/fruitsDB", {useNewUrlParser: true}); const fruitSchema = new mongoose.Schema ({ name: String, rating: Number, review: String }); const Fruit = mongoose.model("Fruit", fruitSchema); Fruit.find((err, fruits) => { if (err) { console.log(err); } else { fruits.forEach((fruit) => console.log(fruit.name)); };…

VIEW QUESTION

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
Back To Top
Search