All other routes on the ~/Locations router work just fine, including adding documents and deleting them... yet this one query returns the above error:Cast to ObjectId failed for value "featured" at path "_id" for model "Location"使用〜/Test-Routes 路由就可以了.推荐答案因为您将router.route('/:id')放在router.route('/featured')之前,所以当您调用/featured时,它将把featured识别为:id并转到Location-Controllers中的viewLocation功能.Because you put router.route('/:id') before router.route('/featured') so when you call to /featured, it will recognize featured as :id and go to your viewLocation function in your Location-Controllers.更改将router.route('/featured')放在router.route('/:id')之前的路线可能会解决此问题.Changing your route to put router.route('/featured') before router.route('/:id') may solve the problem. 这篇关于2个完全相同的路线中的1个的Mongoose/Express CastError吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 19:05