Skip to content

Commit 7695960

Browse files
committed
fix(mongoose): defer to MongoDB driver isValid() for isValidObjectId()
Re: #11227
1 parent 370381a commit 7695960

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

lib/index.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,7 @@ Mongoose.prototype.ObjectId = SchemaTypes.ObjectId;
956956

957957
Mongoose.prototype.isValidObjectId = function(v) {
958958
const _mongoose = this instanceof Mongoose ? this : mongoose;
959-
try {
960-
new _mongoose.Types.ObjectId(v);
961-
} catch (err) {
962-
return false;
963-
}
964-
965-
return true;
959+
return _mongoose.Types.ObjectId.isValid(v);
966960
};
967961

968962
Mongoose.prototype.syncIndexes = function() {

0 commit comments

Comments
 (0)