Mongoose: CastError: Cast to ObjectId failed for value “me” at path “_id” Mongoose: CastError: Cast to ObjectId failed for value “me” at path “_id” mongoose mongoose

Mongoose: CastError: Cast to ObjectId failed for value “me” at path “_id”


You are trying to access a object with findOne by querying _id to be equal to 'me'. Mongoose is attempt to convert the string 'me' to an ObjectId but fails. I can't tell from the traceback if it's your me function which is the issue (that's the only place where findOne is used in the code you have provided), but you could try to change the function call to User.findById(userId, ...) instead. Don't see why userId is equal to 'me' however or if that would help any at all. Hope this gave you some direction at least. Add a comment if you still have problems.


it is old question but since i got the same issue and resolved the issue, I want to post for a future reference.

you get this error because you put

router.get("/:id", controller code)

before

router.get("/me", controller code)

you should always put specific routes before the generic ones.