私はRESTAPIを作成しています。コードを書いた後、POSTMANにエラーメッセージが表示されます。この問題を解決することはできません。エラーNODE.JS、ルート
CODE:
router.route('/messages/:message_id').get(function(req, res) {
Message.findById(req.params.message_id, function(err, message) {
if (err)
res.send(err);
res.json(message);
});
});
エラー、POSTMANとブラウザ:
{
"stack":"Error
at MongooseError.CastError (/home/carlos/www/restapi/node_modules/mongoose/lib/error/cast.js:18:16)
at ObjectId.cast (/home/carlos/www/restapi/node_modules/mongoose/lib/schema/objectid.js:134:13)
at ObjectId.castForQuery (/home/carlos/www/restapi/node_modules/mongoose/lib/schema/objectid.js:187:17)
at module.exports (/home/carlos/www/restapi/node_modules/mongoose/lib/cast.js:205:32)
at Query.cast (/home/carlos/www/restapi/node_modules/mongoose/lib/query.js:2492:10)
at Query.findOne (/home/carlos/www/restapi/node_modules/mongoose/lib/query.js:1237:10)
at Function.findOne (/home/carlos/www/restapi/node_modules/mongoose/lib/model.js:1160:13)
at Function.findById (/home/carlos/www/restapi/node_modules/mongoose/lib/model.js:1097:15)
at /home/carlos/www/restapi/routes.js:40:17
at Layer.handle [as handle_request] (/home/carlos/www/restapi/node_modules/express/lib/router/layer.js:95:5)
at next (/home/carlos/www/restapi/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/carlos/www/restapi/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/carlos/www/restapi/node_modules/express/lib/router/layer.js:95:5)
at /home/carlos/www/restapi/node_modules/express/lib/router/index.js:277:22
at param (/home/carlos/www/restapi/node_modules/express/lib/router/index.js:349:14)
at param (/home/carlos/www/restapi/node_modules/express/lib/router/index.js:365:14)",
"message":"Cast to ObjectId failed for value \"<id>\" at path \"_id\"",
"name":"CastError",
"kind":"ObjectId",
"value":"<id>",
"path":"_id"
}
に動作しますか? – alexmac
localhost:8080/messages/ –
Techtique
実IDを使用するのか、文字列「」を使用していますか? –
alexmac