diff --git a/lib/query.js b/lib/query.js index 212cffd794..99a67d55dd 100644 --- a/lib/query.js +++ b/lib/query.js @@ -2293,9 +2293,9 @@ Query.prototype.mongooseOptions = function(v) { Query.prototype._castConditions = function() { let sanitizeFilterOpt = undefined; - if (this.model != null && this.model.db.options?.sanitizeFilter != null) { + if (this.model?.db.options?.sanitizeFilter != null) { sanitizeFilterOpt = this.model.db.options.sanitizeFilter; - } else if (this.model != null && this.model.base.options?.sanitizeFilter != null) { + } else if (this.model?.base.options?.sanitizeFilter != null) { sanitizeFilterOpt = this.model.base.options.sanitizeFilter; } else { sanitizeFilterOpt = this._mongooseOptions.sanitizeFilter;