From 370381a8a207e67b0847082f5b2a5061cbc90cb3 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 1 Feb 2022 13:04:06 -0500 Subject: [PATCH] fix(mongoose): correctly handle destructured `isValidObjectId` Fix #11304 Re: #11305 --- lib/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index e07d210ee8e..26ce185f030 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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; }