Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
mongoose isValidObjectId() always returns false

I'm having a weird issue with isValidObjectID() in mongoose, which appeared after I added TypeScript to my Node project and had to update mongoose as a result, and force mongoose to use an updated mongodb dependency by overriding it in package.json

"overrides": {
    "mongoose": {
      "mongodb": "^4.3.0"
    }

After doing that, all my tests that involved isValidObjectID() started to fail. I'm pretty sure what's being passed to isValidObjectID() is a valid mongodb object id, but it still returns false.

import { isValidObjectId, Types } from "mongoose";

isValidObjectId('61cc6d8676a69c41fd3408ea'); // returns false
isValidObjectId(new Types.ObjectId('61cc6d8676a69c41fd3408ea')); // returns false

I even tried some of the examples from the documentation that are supposed to return true, but they all return false!

isValidObjectId(new Types.ObjectId()); // returns false!
isValidObjectId('0123456789ab'); // returns false
isValidObjectId(6); // returns false

whereas according to the documentation, they all should return true.

I'm using mongoose version 6.1.9 , and due to package.json override, mongoose is using mongodb version 4.3.1

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

apparently this was a bug in mongoose 6.1.9 updated to mongoose 6.2.0 and it's fixed now

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda