Skip to content

Commit

Permalink
fix(schema): make _getSchema() find path underneath subdocument with …
Browse files Browse the repository at this point in the history
…map of mixed

Fix #12530
  • Loading branch information
vkarpov15 committed Oct 27, 2022
1 parent bd034fa commit 5740c2c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/schema.js
Expand Up @@ -2409,8 +2409,15 @@ Schema.prototype._getSchema = function(path) {
if (p + 1 >= parts.length) {
return foundschema.$__schemaType;
}
const ret = search(parts.slice(p + 1), foundschema.$__schemaType.schema);
return ret;

if (foundschema.$__schemaType instanceof MongooseTypes.Mixed) {
return foundschema.$__schemaType;
}
if (foundschema.$__schemaType.schema != null) {
// Map of docs
const ret = search(parts.slice(p + 1), foundschema.$__schemaType.schema);
return ret;
}
}

foundschema.$fullPath = resultPath.join('.');
Expand Down
13 changes: 13 additions & 0 deletions test/schema.test.js
Expand Up @@ -2885,4 +2885,17 @@ describe('schema', function() {
assert.equal(schema.path('num').instance, 'Decimal128');
assert.equal(schema.path('num2').instance, 'Decimal128');
});

it('_getSchema finds path underneath nested subdocument with map of mixed (gh-12530)', function() {
const schema = new Schema({
child: new Schema({
testMap: {
type: Map,
of: 'Mixed'
}
})
});

assert.equal(schema._getSchema('child.testMap.foo.bar').instance, 'Mixed');
});
});

0 comments on commit 5740c2c

Please sign in to comment.