From d4ad58efc0eecbf3b08e99acb9781d4eb708a633 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Fri, 24 May 2024 12:22:24 -0400 Subject: [PATCH] bring in some changes from #14580 --- lib/query.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/query.js b/lib/query.js index eb6f581f92..c4a413fad1 100644 --- a/lib/query.js +++ b/lib/query.js @@ -2416,14 +2416,20 @@ Query.prototype.merge = function(source) { } opts.omit = {}; - if (this._conditions && Array.isArray(source.$and)) { + if (Array.isArray(source.$and)) { opts.omit['$and'] = true; + if (!this._conditions) { + this._conditions = {}; + } this._conditions.$and = (this._conditions.$and || []).concat( source.$and.map(el => utils.isPOJO(el) ? utils.merge({}, el) : el) ); } - if (this._conditions && Array.isArray(source.$or)) { + if (Array.isArray(source.$or)) { opts.omit['$or'] = true; + if (!this._conditions) { + this._conditions = {}; + } this._conditions.$or = (this._conditions.$or || []).concat( source.$or.map(el => utils.isPOJO(el) ? utils.merge({}, el) : el) );