Issue
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
Solution
apparently this was a bug in mongoose 6.1.9 updated to mongoose 6.2.0 and it's fixed now
Answered By - Rooz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.