Reputation: 33
i am just looking to make an PUT request using Mongoose database. But Its Unable to make any request. I am using postman to pass the data, but no response.
script.js
app.route("/articles/:articleTitle")
.put(function (req, res) {
Article.updateMany(
{ title: req.params.articleTitle },
{ title: req.body.title, content: req.body.content },
{ overwrite: true },
function (err) {
if (!err) {
res.send("Successfully Updated The Data !");
}
}
);
});
here is the code i am using to pass the PUT request in my localhost server but unable to do so.
No Response Here Is The Result
Upvotes: 1
Views: 185
Reputation: 1
.put(function (req, res) {
Article.updateMany(
{ title: req.params.articleTitle },
{ title: req.body.title, content: req.body.content }
)
.then(function (articles) {
res.send(articles);
})
.catch(function (err) {
res.send(err);
});
});
Upvotes: 0
Reputation: 76
app.route("/articles/:articleTitle")
.put(async function (req, res) {
try {
await Article.updateMany(
{ title: req.params.articleTitle },
{ title: req.body.title, content: req.body.content },
{ overwrite: true },
)
res.status(200).send("Successfully Updated The Data !");
} catch (err) {
res.status(500).send("Update failed due to error " + err.message);
}
});
Upvotes: 0
Reputation: 24565
You don't send any response in case of an error, causing the request to hang and never return. Change it to e.g.:
function (err) {
if (!err) {
res.send("Successfully Updated The Data !");
} else {
console.log(err);
res.status(500).send("Update failed due to error " + err.message);
}
}
Upvotes: 2