madhums/node-express-mongoose

Custom get route

BabarRehman opened this issue · 3 comments

Hi Madhum,
We are working on top of your app(which is very nice) but we ran into a very weird problem, We have a controller and created a show method for it, the route is 'app.get("/:id/details, controller.action")' but when we hit the route from the browser we get errors, something on the lines of 'cast to objectID',

Will appreciate any kind of help.

Regards,
Babar Rehman

I think you are having issue with the order of the route.

For example

app.get('/posts/:id', posts.load)
app.get('/posts/details', posts.details)

would cause the cast to objectID error because mongoose tries to find a post with the id details. So you need to order your routes appropriately. Hope you will be able to figure out in your code.

I think I got it what you mean, I will check it tomorrow and let you know.

Sent from Windows Mail

From: Madhusudhan Srinivasa
Sent: ‎Thursday‎, ‎June‎ ‎26‎, ‎2014 ‎8‎:‎28‎ ‎PM
To: madhums/node-express-mongoose
Cc: Babar Rehman

I think you are having issue with the order of the route.

For example
app.get('/posts/:id', posts.load)
app.get('/posts/details', posts.details)

would cause the cast to objectID error because mongoose tries to find a post with the id details. So you need to order your routes appropriately. Hope you will be able to figure out in your code.


Reply to this email directly or view it on GitHub.

Hi Madhum,

I created a load method in the Controller and created the pattern that you followed for the Articles, but now I am not able to get to the controllers details page, any help would be appreciated.