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

174
Views
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 answers
Answer question

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 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!