You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug What is the current behavior?
When passing an ObjectId to isValidObjectId from mongoose.isValidObjectId, it always returns false, no matter what the passed ObjectId has type of string or is an instance of ObjectId. If the current behavior is a bug, please provide the steps to reproduce.
To reproduce, run this code:
const assert = require('assert');
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
const isValidObjectId = mongoose.isValidObjectId;
assert(mongoose.isValidObjectId("5f5f1b2dc802bc22d44a0c2e")); //-> true
assert(isValidObjectId("5f5f1b2dc802bc22d44a0c2e")); //-> false
assert(mongoose.isValidObjectId(new ObjectId("5f5f1b2dc802bc22d44a0c2e"))); // -> true
assert(isValidObjectId(new ObjectId("5f5f1b2dc802bc22d44a0c2e"))); // ->false What is the expected behavior?
It should be true. What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose 6.1.9
Nodejs 17.3.0
The text was updated successfully, but these errors were encountered:
duyhcmut
changed the title
When define const isValidObjectId = mongoose.isValidObjectId, isValidObjectId always return false
When define const isValidObjectId = mongoose.isValidObjectId, isValidObjectId always returns false
Feb 1, 2022
@duyhcmut This is because latest change in v6.1.9 of mongoose. inside isValidObjectId. this is getting referred which is undefined if you use like you mentioned.
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When passing an ObjectId to isValidObjectId from mongoose.isValidObjectId, it always returns false, no matter what the passed ObjectId has type of string or is an instance of ObjectId.
If the current behavior is a bug, please provide the steps to reproduce.
To reproduce, run this code:
const assert = require('assert');
const mongoose = require('mongoose');
const ObjectId = mongoose.Types.ObjectId;
const isValidObjectId = mongoose.isValidObjectId;
assert(mongoose.isValidObjectId("5f5f1b2dc802bc22d44a0c2e")); //-> true
assert(isValidObjectId("5f5f1b2dc802bc22d44a0c2e")); //-> false
assert(mongoose.isValidObjectId(new ObjectId("5f5f1b2dc802bc22d44a0c2e"))); // -> true
assert(isValidObjectId(new ObjectId("5f5f1b2dc802bc22d44a0c2e"))); // ->false
What is the expected behavior?
It should be true.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose 6.1.9
Nodejs 17.3.0
The text was updated successfully, but these errors were encountered: