我一直在跟随thinkster的在线教程“构建你的第一个平均堆栈应用程序”
https://thinkster.io/mean-stack-tutorial#beginning-node
我试图通过使用
测试我的路线以确定其是否正确 <h1>Cast to ObjectId failed for value "57bcdb57bcdb255600e6d114e7afb9" at path "_id"</h1>
并且mongod抛出505错误说
curl http://localhost:8080/<POST ID>/posts
CastError: Cast to ObjectId failed for value "57bcdb57bcdb255600e6d114e7afb9" at path "_id" at MongooseError.CastError (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/error/cast.js:19:11) at ObjectId.cast (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/schema/objectid.js:147:13) at ObjectId.castForQuery (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/schema/objectid.js:187:15) at cast (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/cast.js:208:32) at Query.cast (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/query.js:2653:10) at Query.findOne (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/query.js:1284:10) at /home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/query.js:2230:21 at new Promise.ES6 (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/promise.js:45:3) at Query.exec (/home/ubuntu/workspace/flapper-news/node_modules/mongoose/lib/query.js:2223:10) at /home/ubuntu/workspace/flapper-news/routes/index.js:37:9 at paramCallback (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:404:7) at param (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:384:5) at Function.process_params (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:410:3) at next (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:271:10) at Function.handle (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:176:3) at router (/home/ubuntu/workspace/flapper-news/node_modules/express/lib/router/index.js:46:12)
我通过输入
检查了id和对象是否存在ssml
它验证了一个物体确实在那里
如果您想仔细查看cloud9Workspace
,请访问我的cloud9工作空间我不知道出了什么问题,它可能与我的mongodb版本有关吗? (它比教程中的后一个)
提前感谢您的时间,希望您能提供帮助!
答案 0 :(得分:1)
看起来你作为ObjectID传递的字符串格式不正确(它太长了)。 Mongo ObjectID是24个字符(12个字节)的字符串。您的特定ID有30个字符