Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
Mongoose refuses to cast valid string to ObjectId

I return the Document _id and use it as a req.params.id to get the document at a later stage.

ObjectId.isValid() returns true, then using it in either ObjectId() or Find or FindOne will result in a cast error or

hex is not a function.

Basically also copy pasted the _id straight from the database to test.

I'm using mongoose ^4.7.6; _id looks like: 586e30a597f85b69891df304

[Stack trace]

[CastError: Cast to ObjectId failed for value "586e30a597f85b69891df304" at path "_id" for model "Module"] message: 'Cast to ObjectId failed for value "586e30a597f85b69891df304" at path "_id" for model "Module"', name: 'CastError', stringValue: '"586e30a597f85b69891df304"', kind: 'ObjectId', value: '586e30a597f85b69891df304', path: '_id', reason: undefined,

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

this is a bug in Mongoose >=4.7.3 https://github.com/Automattic/mongoose/issues/4867

bson package is really buggy

over 4 years ago · Santiago Trujillo Relatório

0

Turns out it's a bug in that version of mongoose. Removing my node_modules and reinstalling with mongoose set to 4.3.3 fixed this issue.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda