0

I am having an error that I do not understand how it happens. If I have my routes in the following order: enter image description here

My controller obter_todos_precos is just a console.log and is not using any Model, but i am getting the following error:

"message": "Cast to ObjectId failed for value \"preco\" at path \"_id\" for 
model \"ZonaModel\""

I have found a solution by changing the order of the routes in this way: enter image description here

Why I am having this behavior?

Ricardo Martin
  • 129
  • 1
  • 8

1 Answers1

2

The router matches the first route it match /:id_zona and /preco route to the same path as preco can also be a value for id_zona

so when /preco is above it works, whereas when /:id_zona is above and you trying to use /preco the the route matches to /:id_zona and the value of id_zona is preco which in you controller wished to be of ObjectId type

Eftakhar
  • 455
  • 4
  • 17