skip to Main Content

Mongodb – How to fix Error: CastError: Cast to ObjectId failed for value (type string) at path "_id" for model

My current code for the /api/students/id route is as follows router.get('/:id',asyncHandler(async(req,res)=>{ const student = await Student.findById(req.params.id) if(student){ res.json(student) } else{ res.status(404).json({message: 'Student not found'}) } })) export default router When I hit the /api/students/{correct-Id} it gives me the correct students…

VIEW QUESTION
Back To Top
Search