Daniel
Daniel

Reputation: 27

Axios PUT request failed with 500 code Cast to ObjectId failed for value

I'm new to MERN stack and I'm trying to make a put request with axios to change the user profile information but I'm getting the following error as a response : {"message":"Cast to ObjectId failed for value "profile" (type string) at path "_id" for model "User""} Here is the entire project : https://github.com/burNN11/new-project

Upvotes: 1

Views: 173

Answers (1)

bmz1
bmz1

Reputation: 188

So you have the following in the router:

  • router.put('/:id')
  • router.put('/profile')

When you make a PUT request to /profile, express will invoke the first route (/:id), and treats profile as an id.

Solution: change your route name to PUT /profile/:id

Upvotes: 1

Related Questions