From 51c6776a9a67368cd2cb1cf170996912353ee204 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 25 Nov 2019 17:40:32 -0500 Subject: [PATCH] refactor(schema): add array.$, array.$.$ subpaths for nested arrays Fix #6405 --- lib/schema.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/schema.js b/lib/schema.js index 1aac5594522..2504c14059c 100644 --- a/lib/schema.js +++ b/lib/schema.js @@ -672,16 +672,17 @@ Schema.prototype.path = function(path, obj) { let arrayPath = path; let _schemaType = schemaType; - let toAdd = []; + const toAdd = []; while (_schemaType.$isMongooseArray) { arrayPath = arrayPath + '.$'; // Skip arrays of document arrays if (_schemaType.$isMongooseDocumentArray) { - toAdd = []; - break; + _schemaType = _schemaType.$embeddedSchemaType.clone(); + } else { + _schemaType = _schemaType.caster.clone(); } - _schemaType = _schemaType.caster.clone(); + _schemaType.path = arrayPath; toAdd.push(_schemaType); }