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

413
Views
¿Por qué obtengo am CastError: Cast to ObjectId falló?

Obtengo lo siguiente cuando llamo a una ruta en mi proyecto:

 serveur running PORT: 7000 /user/new CastError: Cast to ObjectId failed for value "favicon.ico" (type string) at path "_id" for model "User" at model.Query.exec (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\query.js:4650:21) at model.Query.Query.then (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\query.js:4749:15) at exports.findOneUser (C:\Users\Admin\Downloads\books\routes\homeController.js:38:6) at Layer.handle [as handle_request] (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\layer.js:95:5) at next (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\layer.js:95:5) at C:\Users\Admin\Downloads\books\node_modules\express\lib\router\index.js:281:22 at param (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\index.js:360:14) at param (C:\Users\Admin\Downloads\books\node_modules\express\lib\router\index.js:371:14) { messageFormat: undefined, stringValue: '"favicon.ico"', kind: 'ObjectId', value: 'favicon.ico', path: '_id', reason: BSONTypeError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters at new BSONTypeError (C:\Users\Admin\Downloads\books\node_modules\bson\lib\error.js:41:28) at new ObjectId (C:\Users\Admin\Downloads\books\node_modules\bson\lib\objectid.js:65:23) at castObjectId (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\cast\objectid.js:24:12) at ObjectId.cast (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\schema\objectid.js:247:12) at ObjectId.SchemaType.applySetters (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\schematype.js:1180:12) at ObjectId.SchemaType._castForQuery (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\schematype.js:1614:15) at ObjectId.SchemaType.castForQuery (C:\Users\Admin\Downloads\books\node_modules\mongoose\lib\schematype.js:1604:15)

Tengo una ruta (como route.get("/", myCallBack) ) que devuelve todos los objetos en mi base de datos mongodb. No puedo encontrar donde está mi error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema es que no es una cadena _id válida. Tiene que ser una cadena binaria de 12 bytes o una cadena de 24 bytes hexadecimales. "favicon.ico" tampoco lo es.

about 4 years ago · Juan Pablo Isaza 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!