, ,

Recently I encountered this mongoose error CastError: Cast to ObjectId failed for value \”583fe2c488cf652d4c6b45d1\” at path
\”_id\” for model User

In the script, I simply pass the documentId as a string!!
User.findOne({‘_id’: docId}).exec()…

So I run a command

npm list --depth=0

to check the mongodb and mongoose version.
Heres the report:
├── mongodb@2.2.19
├── mongoose@4.7.2

It seems theres an issue on this mongodb version, so what I did is I uninstall and try to use different version such as 2.2.16
$ npm uninstall mongodb,it will delete the mongodb from your node_modules directory
$ npm install mongodb@2.2.16
Finally, restart the app and it works fine!

Related article:
Mongodb error: hex is not a function