Hello I am trying to put the type value in my mongodb database using rest api. However, it shows an error saying cannot put (404 not found).
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);
});
});
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);
}
Hello I am trying to put the type value in my mongodb database using rest api. However, it shows an error saying cannot put (404 not found).
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);
});
});
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);
}
Share
Improve this question
asked May 30, 2017 at 18:50
Ankur ChavdaAnkur Chavda
1736 silver badges17 bronze badges
0
3 Answers
Reset to default 6Use '/api/types/:_id'
rather than 'api/types/:_id'
One more issue which causes the mentioned error:
Check if there is any typo mistake in the URL which you are trying to access.
In my case, I tried accessing
"/api/users/udpate/:id"
instead of
"/api/users/update/:id"
I have entered udpate instead of update.So express will not be able to find the route which causes this error.
Two solutions can be of this issue:
Can be a typo in endpoints.
Instead of this
"uesr/:userId"
Check for this
"/user/:userId"
Can be a slash missing in starting.
Instead of this
"user/:userId"
Add this slash in starting
"/user/:userId"