enter image description here building app on express and mongoose mongodb. when trying to get to /musics/:id to get to details page app is sending me to correct page and it is crashing because id is changed
app.get("/musics/:id", async (req, res) => {
console.log(req.params);
const { id } = req.params;
const music = await Music.findById(id);
res.render("./music/edit", { music });
});
here is error
DATABASE CONNECTED!
{ id: '625d0fb066f8544535a2466d' }
{ id: 'Roboto-Regular.ttf' }
C:UsersakbarOneDriveРабочий столMusicApp2.0node_modulesmongooselibquery.js:4715
const castError = new CastError();
^
CastError: Cast to ObjectId failed for value "Roboto-Regular.ttf" (type string) at path "_id" for model "Music"
at model.Query.exec (C:UsersakbarOneDriveРабочий столMusicApp2.0node_modulesmongooselibquery.js:4715:21)
at model.Query.Query.then (C:UsersakbarOneDriveРабочий столMusicApp2.0node_modulesmongooselibquery.js:4814:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
messageFormat: undefined,
stringValue: '"Roboto-Regular.ttf"',
kind: 'ObjectId',
value: 'Roboto-Regular.ttf',
path: '_id',
reason: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer
2
Answers
as suggested in comments changing route url helped
Try a different function
Change
To