mongoose SingleNestedPath compatability added for subdocument queries

This commit is contained in:
Dan Ribbens
2019-09-26 15:23:42 -04:00
parent e4ef4be7b6
commit 43af2c3dc5

View File

@@ -97,14 +97,14 @@ function parseParam(key, val, model, query, locale) {
function parseSchemaForKey(schema, query, keyPrefix, lcKey, val, operator, locale) {
let paramType;
let key = keyPrefix + lcKey;
let matches = lcKey.match(/(.+)\.(.+)/);
if (matches) {
// Parse SubSchema
if (schema.paths[matches[1]].constructor.name === 'DocumentArray' ||
schema.paths[matches[1]].constructor.name === 'Mixed') {
parseSchemaForKey(schema.paths[matches[1]].schema, `${matches[1]}.`, matches[2], val, operator)
} else if (schema.paths[matches[1]].constructor.name === 'SchemaType') {
} else if (schema.paths[matches[1]].constructor.name === 'SchemaType' ||
schema.paths[matches[1]].constructor.name === 'SingleNestedPath') {
// This wasn't handled in the original package but seems to work
paramType = schema.paths[matches[1]].schema.paths.name.instance;
}