alex diaz
alex diaz

Reputation: 1

Having trouble with Mongod testing a route

I've been following the online tutorial at thinkster "building your first mean stack app" at

https://thinkster.io/mean-stack-tutorial#beginning-node

im trying to test my route to see if its correct by using

    curl -X PUT http://localhost:8080/posts/<POST ID>/upvote

and mongod throws a 505 error saying

    <h1>Cast to ObjectId failed for value &#34;57bcdb57bcdb255600e6d114e7afb9&#34; at path &#34;_id&#34;</h1>

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)

I checked to see if id and object existed by entering

    curl http://localhost:8080/<POST ID>/posts 

and it verified that an object was indeed there

here is my cloud9 workspace if you want to take a closer look cloud9Workspace

i have no idea what went wrong, could it be possible that it has to do with my mongodb version? (its a later one than in the tutorial)

thank you in advance for your time , hope you can help!

Upvotes: 0

Views: 79

Answers (1)

Dave V
Dave V

Reputation: 1976

It looks like the string you are passing as an ObjectID is malformed (it's too long). Mongo ObjectIDs are 24 characters (12-byte) strings. Your particular ID has 30 characters

Upvotes: 1

Related Questions