{"record":{"id":"dda73fc3863f65b7","repo":"Automattic/mongoose","slug":"cannot-set-both-validateallpaths-and-pathstoval","errorCode":null,"errorMessage":"Cannot set both `validateAllPaths` and `pathsToValidate`","messagePattern":"Cannot set both `validateAllPaths` and `pathsToValidate`","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/document.js","lineNumber":2808,"sourceCode":"        ('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\n      for (const path of paths) {\n        const schemaType = this.$__schema.path(path);\n        if (!schemaType?.$isMongooseArray) {","sourceCodeStart":2790,"sourceCodeEnd":2826,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/document.js#L2790-L2826","documentation":"TypeError from Document#validate(): the call passed both an explicit pathsToValidate (first argument, string or array) and `validateAllPaths: true` in options. Selecting specific paths and selecting all paths are mutually exclusive, so validate() refuses the combination.","triggerScenarios":"`doc.validate(['name'], { validateAllPaths: true })` or `doc.validate('name', { validateAllPaths: true })`.","commonSituations":"A wrapper that always forwards a paths argument while the caller adds validateAllPaths; refactors from path-list validation to full validation that forget to clear the first argument.","solutions":["Drop the first argument when using validateAllPaths","Or drop validateAllPaths and keep the explicit path list","Make wrapper functions normalize arguments so both are never set together"],"exampleFix":"// before\nawait doc.validate(['name', 'email'], { validateAllPaths: true });\n\n// after\nawait doc.validate({ validateAllPaths: true });\n// or: await doc.validate(['name', 'email']);","handlingStrategy":"validation","validationCode":"function normalizeValidateArgs(paths, opts = {}) {\n  if (opts.validateAllPaths && paths != null) {\n    if (typeof paths !== 'object' || Array.isArray(paths)) return [null, opts]; // drop paths\n  }\n  return [paths, opts];\n}\nconst [p, o] = normalizeValidateArgs(paths, opts);\nawait doc.validate(p, o);","typeGuard":null,"tryCatchPattern":"try {\n  await doc.validate(paths, opts);\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('validateAllPaths')) {\n    // paths argument conflicts with validateAllPaths; call with options only\n  } else { throw err; }\n}","preventionTips":["When switching to validateAllPaths, remove the first (paths) argument","Audit wrapper functions that always forward a paths argument"],"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"}