(doc, paths)
| 3178 | } |
| 3179 | |
| 3180 | function _addArrayPathsToValidate(doc, paths) { |
| 3181 | for (const path of paths) { |
| 3182 | const _pathType = doc.$__schema.path(path); |
| 3183 | if (!_pathType) { |
| 3184 | continue; |
| 3185 | } |
| 3186 | |
| 3187 | if (!_pathType.$isMongooseArray || |
| 3188 | // To avoid potential performance issues, skip doc arrays whose children |
| 3189 | // are not required. `getPositionalPathType()` may be slow, so avoid |
| 3190 | // it unless we have a case of #6364 |
| 3191 | (!Array.isArray(_pathType) && |
| 3192 | _pathType.$isMongooseDocumentArray && |
| 3193 | !_pathType?.schemaOptions?.required)) { |
| 3194 | continue; |
| 3195 | } |
| 3196 | |
| 3197 | // gh-11380: optimization. If the array isn't a document array and there's no validators |
| 3198 | // on the array type, there's no need to run validation on the individual array elements. |
| 3199 | if (_pathType.$isMongooseArray && |
| 3200 | !_pathType.$isMongooseDocumentArray && // Skip document arrays... |
| 3201 | !_pathType.embeddedSchemaType.$isMongooseArray && // and arrays of arrays |
| 3202 | _pathType.embeddedSchemaType.validators.length === 0) { |
| 3203 | continue; |
| 3204 | } |
| 3205 | |
| 3206 | const val = doc.$__getValue(path); |
| 3207 | _pushNestedArrayPaths(val, paths, path); |
| 3208 | } |
| 3209 | } |
| 3210 | |
| 3211 | function _pushNestedArrayPaths(val, paths, path) { |
| 3212 | if (val != null) { |
no test coverage detected