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;