Search code examples
node.jsroutespostmanobjectid

node.js Cast to ObjectId error on postman but I don't user any variable, I'm just testing the route


I have an error on postman that I don't undersand.
When I create a new route I test it "empty" to be sure that the requests passes.
So I just did a new route like that :

router.get("/responses", async (req, res) => {
  res.send("route ok");
});

module.exports = router;

But on postman when I try the route I have this error :
"error": "Cast to ObjectId failed for value "responses" at path "_id" for model "Survey""

I don't know why I got this error because I don't use any model in this route.

I checked the other routes and because I read on forums that if there is a route with the same path but with like :id in the end, the routes have to be switched in order but I don't have an other route with that name and I can rename with whatever name I want, the error remains.

All my others routes are working fine so I really don't understand what the problem is.
Any help would be appreciated.

Screenshot from postman postman


Solution

  • Double check the url on Postman and also the request method make sure it's GET, maybe share an image of postman window to see what's going on.