From 3c46ed07b6b686783c0f60aa1ec4a89922604a52 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 7 Jun 2022 12:45:43 -0400 Subject: [PATCH] fix: avoid unnecessarily creating object every time calling schema.discriminator() re: #11855 --- lib/schema.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/schema.js b/lib/schema.js index c8453fa4307..6464e6c8b52 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -503,7 +503,7 @@ Schema.prototype.defaultOptions = function(options) { */ Schema.prototype.discriminator = function(name, schema) { - this._applyDiscriminators = Object.assign({}, this._applyDiscriminators, { [name]: schema }); + this._applyDiscriminators = Object.assign(this._applyDiscriminators || {}, { [name]: schema }); return this; };