Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

618
Views
La identificación utilizada para encontrar el objeto de la base de datos está cambiando a pedido

ingrese la descripción de la imagen aquí construyendo la aplicación en express y mongoose mongodb. cuando trato de acceder a /musics/:id para llegar a la página de detalles, la aplicación me envía a la página correcta y se bloquea porque se cambió la identificación

 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 }); });

aquí hay un error

 DATABASE CONNECTED! { id: '625d0fb066f8544535a2466d' } { id: 'Roboto-Regular.ttf' } C:\Users\akbar\OneDrive\Рабочий стол\MusicApp2.0\node_modules\mongoose\lib\query.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:\Users\akbar\OneDrive\Рабочий стол\MusicApp2.0\node_modules\mongoose\lib\query.js:4715:21) at model.Query.Query.then (C:\Users\akbar\OneDrive\Рабочий стол\MusicApp2.0\node_modules\mongoose\lib\query.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

aquí el código fuente

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

como se sugiere en los comentarios, cambiar la URL de la ruta ayudó

 app.get("/musics/:id/details", async (req, res) => { const { id } = req.params; const music = await Music.findById(id); res.render("./music/edit", { music }); });
over 4 years ago · Santiago Trujillo Report

0

Pruebe una función diferente

 await Music.findOne({_id: id})

Cambio

 res.render("./music/edit", { music });

A

 res.render("music/edit", { music });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!