From 978d695fb2f2714cc6c87978c560abda7b71de12 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sun, 4 Oct 2020 13:24:52 -0400 Subject: [PATCH] fix(schema): handle setting nested paths underneath single nested subdocs Fix #9459 --- lib/schema.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index 07f760453ac..1ad65525857 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -715,6 +715,9 @@ Schema.prototype.path = function(path, obj) { this.singleNestedPaths[path + '.' + key] = schemaType.schema.subpaths[key]; } + for (const key in schemaType.schema.nested) { + this.singleNestedPaths[path + '.' + key] = 'nested'; + } Object.defineProperty(schemaType.schema, 'base', { configurable: true, @@ -1124,8 +1127,10 @@ Schema.prototype.pathType = function(path) { if (this.subpaths.hasOwnProperty(cleanPath) || this.subpaths.hasOwnProperty(path)) { return 'real'; } - if (this.singleNestedPaths.hasOwnProperty(cleanPath) || this.singleNestedPaths.hasOwnProperty(path)) { - return 'real'; + + const singleNestedPath = this.singleNestedPaths.hasOwnProperty(cleanPath) || this.singleNestedPaths.hasOwnProperty(path); + if (singleNestedPath) { + return singleNestedPath === 'nested' ? 'nested' : 'real'; } // Look for maps