problem description
use mongoose to manipulate data in MongoDB Atlas
when adding data, if I use res.json (data) to try to refresh the data on the page, only one data in json format will be displayed on the page
but when I delete the data, if I do this, it will refresh the data on the page, that is, to achieve the effect I want
but when I was watching the video of Big Rails365, he also used res.json (data) to add data, and succeeded
.want to know why this is QAQ
attached node teaching video link: ideo/av20196752/?p=17" rel=" nofollow noreferrer "> node-TodoList
related codes
/ / Please paste the code text below (do not replace the code with pictures)
app.post("/todo", function (req, res) {
Todo(req.body).save(function (err, data) {
if (err) {
throw err;
}
console.log(data);
res.json(data);
});
});
app.delete("/todo/:item", function (req, res) {
// data = data.filter(function (todo) {
// return todo.item.replace(/ /g, "-") !== req.params.item;
// });
Todo.find({
item: req.params.item.replace(/-/g, " ")
}).remove(function (err, data) {
if (err) {
throw err;
}
console.log(data);
res.json(data);
})
});
post returns the result
delete returns normal results, which means that the items to be deleted in the list are missing
I also hope the passing bosses will give us some advice. Thank you very much
.