您好,我正在尝试使用rest api 将类型值放入我的mongodb 数据库中。但是,它显示错误,指出无法放置(404 未找到)。
app.js
app.put('api/types/:_id', function(req,res){
var id = req.params._id;
var type = req.body;
Type.updateType(id, type, {}, function(err, type){
if(err){
throw err;
}
res.json(type);
});
});
类型.js
module.exports.updateType = function(id, type, options, callback){
var query = {_id: id};
var update = {
name: type.name,
description: type.description,
category: type.category
}
Task.findOneAndUpdate(query,update, options, callback);
}
最佳答案
使用'/api/types/:_id'
而不是'api/types/:_id'
关于javascript - 无法使用 Node js 将错误放入 REST API 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44269779/