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

449
Visualizações
values passed to the '_id' (mongodb) is not a valid ObjectId Pymongo

I have a python script that receive (from a node.js script) an _id for a mongodb document as an argument. Using that value I'm trying to query the db and retrieve a document.

However, when i try to run the script it throws an error saying

"'xxxxxxxxxx' is not a valid ObjectId, it must be a 12-byte input or a 24-character hex string".

my script where the error is causing:

result = db.req.find_one({"_id": ObjectId(sys.argv[1])})

When i check the type() of the sys.argv[1] it says str. I thought wrapping the string around ObjectId should do the trick.

value of sys.argv[1] when printed: '"5902fbdd4d2f430dfe2dded4"'

Anyone one know whats the reason causing the issue?

Thanks in advance.

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

0

Resolved:

I removed the JSON.stringify() bit from the passing value in the node.js script. All seems fine now.

over 4 years ago · Santiago Trujillo Relatório

0

MongoDB allows storing "_id" in "ObjectId" format.

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