(doc, paths)
| 3241 | } |
| 3242 | |
| 3243 | function _addArrayPathsToValidate(doc, paths) { |
| 3244 | for (const path of paths) { |
| 3245 | const _pathType = doc.$__schema.path(path); |
| 3246 | if (!_pathType) { |
| 3247 | continue; |
| 3248 | } |
| 3249 | |
| 3250 | if (!_pathType.$isMongooseArray || |
| 3251 | // To avoid potential performance issues, skip doc arrays whose children |
| 3252 | // are not required. `getPositionalPathType()` may be slow, so avoid |
| 3253 | // it unless we have a case of #6364 |
| 3254 | (!Array.isArray(_pathType) && |
| 3255 | _pathType.$isMongooseDocumentArray && |
| 3256 | !_pathType?.schemaOptions?.required)) { |
| 3257 | continue; |
| 3258 | } |
| 3259 | |
| 3260 | // gh-11380: optimization. If the array isn't a document array and there's no validators |
| 3261 | // on the array type, there's no need to run validation on the individual array elements. |
| 3262 | if (_pathType.$isMongooseArray && |
| 3263 | !_pathType.$isMongooseDocumentArray && // Skip document arrays... |
| 3264 | !_pathType.embeddedSchemaType.$isMongooseArray && // and arrays of arrays |
| 3265 | _pathType.embeddedSchemaType.validators.length === 0) { |
| 3266 | continue; |
| 3267 | } |
| 3268 | |
| 3269 | const val = doc.$__getValue(path); |
| 3270 | _pushNestedArrayPaths(val, paths, path); |
| 3271 | } |
| 3272 | } |
| 3273 | |
| 3274 | function _pushNestedArrayPaths(val, paths, path) { |
| 3275 | if (val != null) { |
no test coverage detected