From 6c09419091b3da3f868ca1c345dece068516ffdd Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Wed, 3 Mar 2021 17:45:06 -0500 Subject: [PATCH] fix(query): handle embedded discriminator paths on `$push` Re: #9977 --- lib/helpers/query/castUpdate.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/helpers/query/castUpdate.js b/lib/helpers/query/castUpdate.js index bf60e5d11b7..1ee20fb41f2 100644 --- a/lib/helpers/query/castUpdate.js +++ b/lib/helpers/query/castUpdate.js @@ -203,6 +203,13 @@ function walkUpdatePath(schema, obj, op, options, context, filter, pref) { // watch for embedded doc schemas schematype = schema._getSchema(prefix + key); + if (schematype == null) { + const _res = getEmbeddedDiscriminatorPath(schema, obj, filter, prefix + key); + if (_res.schematype != null) { + schematype = _res.schematype; + } + } + if (op !== '$setOnInsert' && handleImmutable(schematype, strict, obj, key, prefix + key, context)) { continue;