(doc, paths)
| 3275 | } |
| 3276 | |
| 3277 | function _addArrayPathsToValidate(doc, paths) { |
| 3278 | for (const path of paths) { |
| 3279 | const _pathType = doc.$__schema.path(path); |
| 3280 | if (!_pathType) { |
| 3281 | continue; |
| 3282 | } |
| 3283 | |
| 3284 | if (!_pathType.$isMongooseArray || |
| 3285 | // To avoid potential performance issues, skip doc arrays whose children |
| 3286 | // are not required. `getPositionalPathType()` may be slow, so avoid |
| 3287 | // it unless we have a case of #6364 |
| 3288 | (!Array.isArray(_pathType) && |
| 3289 | _pathType.$isMongooseDocumentArray && |
| 3290 | !_pathType?.schemaOptions?.required)) { |
| 3291 | continue; |
| 3292 | } |
| 3293 | |
| 3294 | // gh-11380: optimization. If the array isn't a document array and there's no validators |
| 3295 | // on the array type, there's no need to run validation on the individual array elements. |
| 3296 | if (_pathType.$isMongooseArray && |
| 3297 | !_pathType.$isMongooseDocumentArray && // Skip document arrays... |
| 3298 | !_pathType.embeddedSchemaType.$isMongooseArray && // and arrays of arrays |
| 3299 | _pathType.embeddedSchemaType.validators.length === 0) { |
| 3300 | continue; |
| 3301 | } |
| 3302 | |
| 3303 | const val = doc.$__getValue(path); |
| 3304 | _pushNestedArrayPaths(val, paths, path); |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | function _pushNestedArrayPaths(val, paths, path) { |
| 3309 | if (val != null) { |
no test coverage detected