{"record":{"id":"4112281777d9739d","repo":"Automattic/mongoose","slug":"cannot-set-both-validateallpaths-and-pathstoski","errorCode":null,"errorMessage":"Cannot set both `validateAllPaths` and `pathsToSkip`","messagePattern":"Cannot set both `validateAllPaths` and `pathsToSkip`","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/document.js","lineNumber":2805,"sourceCode":"\n    const hasValidateModifiedOnlyOption = options &&\n        (typeof options === 'object') &&\n        ('validateModifiedOnly' in options);\n\n    const pathsToSkip = options?.pathsToSkip || null;\n\n    let shouldValidateModifiedOnly;\n    if (hasValidateModifiedOnlyOption) {\n      shouldValidateModifiedOnly = !!options.validateModifiedOnly;\n    } else {\n      shouldValidateModifiedOnly = this.$__schema.options.validateModifiedOnly;\n    }\n    this.$__.validateModifiedOnly = shouldValidateModifiedOnly;\n\n    const validateAllPaths = options?.validateAllPaths;\n    if (validateAllPaths) {\n      if (pathsToSkip) {\n        throw new TypeError('Cannot set both `validateAllPaths` and `pathsToSkip`');\n      }\n      if (pathsToValidate) {\n        throw new TypeError('Cannot set both `validateAllPaths` and `pathsToValidate`');\n      }\n      if (hasValidateModifiedOnlyOption && shouldValidateModifiedOnly) {\n        throw new TypeError('Cannot set both `validateAllPaths` and `validateModifiedOnly`');\n      }\n    }\n\n    const _this = this;\n\n    // only validate required fields when necessary\n    let paths;\n    let doValidateOptionsByPath;\n    if (validateAllPaths) {\n      paths = new Set(Object.keys(this.$__schema.paths));\n      // gh-661: if a whole array is modified, make sure to run validation on all\n      // the children as well","sourceCodeStart":2787,"sourceCodeEnd":2823,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/document.js#L2787-L2823","documentation":"TypeError from Document#validate(): the options object combined `validateAllPaths: true` with `pathsToSkip`. `validateAllPaths` means 'validate every path in the schema', so asking it to also skip paths is contradictory and rejected before validation starts.","triggerScenarios":"`doc.validate({ validateAllPaths: true, pathsToSkip: ['name'] })` or `pathsToSkip: 'name email'` (string form) in the same options object.","commonSituations":"Refactoring validation options incrementally and leaving both knobs set; spreading a shared defaults object that already contains pathsToSkip into a call that adds validateAllPaths.","solutions":["Remove `pathsToSkip` when using validateAllPaths","Or drop validateAllPaths and keep pathsToSkip to validate everything except a few paths","Audit shared/spread options objects so only one scoping mechanism survives"],"exampleFix":"// before\nawait doc.validate({ validateAllPaths: true, pathsToSkip: ['name'] });\n\n// after\nawait doc.validate({ validateAllPaths: true });\n// or the inverse: await doc.validate({ pathsToSkip: ['name'] });","handlingStrategy":"validation","validationCode":"function assertValidateOptions(opts = {}) {\n  if (opts.validateAllPaths && opts.pathsToSkip) {\n    throw new TypeError('Choose either validateAllPaths or pathsToSkip, not both');\n  }\n}\nassertValidateOptions(opts);\nawait doc.validate(opts);","typeGuard":null,"tryCatchPattern":"try {\n  await doc.validate(opts);\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('validateAllPaths')) {\n    // options conflict; rebuild opts with exactly one scoping mechanism\n  } else { throw err; }\n}","preventionTips":["Pass exactly one scoping mechanism: validateAllPaths, pathsToValidate, or pathsToSkip","Do not spread generic defaults objects into validation options"],"tags":["mongoose","validate","options","typeerror"],"backgroundTag":"conflicting-validation-options","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}