Skip to content

Commit

Permalink
fix(mongoose): correctly handle destructured isValidObjectId
Browse files Browse the repository at this point in the history
Fix #11304
Re: #11305
  • Loading branch information
vkarpov15 committed Feb 1, 2022
1 parent 9f897ea commit 370381a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,9 @@ Mongoose.prototype.ObjectId = SchemaTypes.ObjectId;
*/

Mongoose.prototype.isValidObjectId = function(v) {
const _mongoose = this instanceof Mongoose ? this : mongoose;
try {
new this.Types.ObjectId(v);
new _mongoose.Types.ObjectId(v);
} catch (err) {
return false;
}
Expand Down

0 comments on commit 370381a

Please sign in to comment.