【问题标题】:Reacord deleted from the database but getting an error :- Request failed with status code 404 using axios, node, mongo and KoaReacord 从数据库中删除但出现错误:- 使用 axios、node、mongo 和 Koa 请求失败,状态码为 404
【发布时间】:2020-06-03 05:52:12
【问题描述】:

数据已成功删除,但我收到错误代码 GET http://localhost:3000/api/deletetagbyid/5e4d896cea390804241612cd 404 (Not Found)。

任何人都可以帮助我实际上我是反应节点的新手:- 谢谢你

// Delete Discount Tag Using Axios :-
const handleDelete = async (e, id) => {

    if (confirm("Are you sure. You Want to delete this tag?")) {

        await axios.get("/api/deletetagbyid/" + id).then((result) => {
            console.log(result);
        }).catch(() => {
            console.log('Error Occured');
        });
    }
}

// This is the backend code to delete data with koa js :-
exports.deletetagbyid = (ctx) => {

    let id = ctx.params.id;
    Note.findOne({
        "_id": ObjectID(id)
    }, function (err, docs) {

        if (!docs) {
            ctx.body = 404;
        } else {
            Note.deleteOne({
                _id: id
            }, function (err, obj) {
                if (err) throw err;
                ctx.body = "Deleted SuccessFully";
                console.log(" document(s) deleted");
            });
        }
    })
};

// This is the route for delete data :-
router.get('/api/deletetagbyid/:id', discounttag.deletetagbyid);

【问题讨论】:

    标签: node.js reactjs mongodb koa


    【解决方案1】:

    对不起,不要使用 get 方法从数据库中删除记录使用 DELETE 方法

    对于你的问题,我认为你调用了两次 delete api

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      • 2017-05-31
      • 2022-11-13
      • 2021-04-10
      • 2020-04-05
      • 2020-09-18
      • 2019-10-12
      相关资源
      最近更新 更多