{"record":{"id":"d49ca5385f868c6a","repo":"Automattic/mongoose","slug":"could-not-find-path-filterpath-in-schema","errorCode":null,"errorMessage":"Could not find path \"${filterPath}\" in schema","messagePattern":"Could not find path \"(.+?)\" in schema","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/helpers/update/castArrayFilters.js","lineNumber":104,"sourceCode":"      } else {\n        // If there are multiple array filters in the path being updated, make sure\n        // to replace them so we can get the schema path.\n        filterPathRelativeToBase = cleanPositionalOperators(filterPathRelativeToBase);\n        schematype = getPath(filterBaseSchema, filterPathRelativeToBase, discriminatorValueMap);\n      }\n\n      if (schematype == null) {\n        if (!strictQuery) {\n          return;\n        }\n        const filterPath = filterPathRelativeToBase == null ?\n          baseFilterPath + '.0' :\n          baseFilterPath + '.0' + filterPathRelativeToBase;\n        // For now, treat `strictQuery = true` and `strictQuery = 'throw'` as\n        // equivalent for casting array filters. `strictQuery = true` doesn't\n        // quite work in this context because we never want to silently strip out\n        // array filters, even if the path isn't in the schema.\n        throw new Error(`Could not find path \"${filterPath}\" in schema`);\n      }\n      if (typeof filter[key] === 'object') {\n        filter[key] = castFilterPath(query, schematype, filter[key]);\n      } else {\n        filter[key] = schematype.castForQuery(null, filter[key]);\n      }\n    }\n  }\n}\n","sourceCodeStart":86,"sourceCodeEnd":114,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/helpers/update/castArrayFilters.js#L86-L114","documentation":"When strictQuery is enabled (true or 'throw'), Mongoose requires every path referenced inside arrayFilters to exist in the schema; unknown paths throw this Error during update casting instead of being passed through to MongoDB. strictQuery true and 'throw' are deliberately equivalent here because silently stripping an array filter would change which elements the update touches.","triggerScenarios":"Model.updateOne({}, { $set: { 'items.$[e].status': 2 } }, { arrayFilters: [{ 'e.someField.notInSchema': true }]) with strictQuery: true (query option, schema option, or inherited from a strict schema) where items.someField is not defined in the schema.","commonSituations":"Collections holding fields that exist in MongoDB but were never declared in the Mongoose schema (schema drift); enabling strictQuery globally for security and breaking older queries; typos in the sub-paths of array filter identifiers.","solutions":["Add the missing path to the (sub)document schema","Fix the typo in the array filter path so it matches a schema path","Relax strict query mode for this update: pass { strictQuery: false } in the update options (or set strictQuery: false on the schema)"],"exampleFix":"// before\nawait Model.updateOne({}, { $set: { 'items.$[e].status': 2 } },\n  { strictQuery: true, arrayFilters: [{ 'e.extraField': true }] }); // extraField not in schema\n\n// after\nconst schema = new Schema({ items: [{ status: Number, extraField: Boolean }] });\nawait Model.updateOne({}, { $set: { 'items.$[e].status': 2 } },\n  { strictQuery: true, arrayFilters: [{ 'e.extraField': true }] });","handlingStrategy":"validation","validationCode":"// Check every array-filter path exists in the schema before updating\nfunction arrayFilterPathsExist(schema, filters) {\n  for (const f of filters) {\n    for (const p of Object.keys(f)) {\n      const sub = p.split('.').slice(1).join('.'); // drop identifier prefix like 'e.'\n      if (sub && !schema.path(`items.0.${sub}`) && !schema.path(`items.${sub}`)) return false;\n    }\n  }\n  return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await Model.updateOne(f, u, { strictQuery: true, arrayFilters });\n} catch (err) {\n  if (/Could not find path .* in schema/.test(err.message)) {\n    // add the path to the schema or re-run with { strictQuery: false }\n  } else throw err;\n}","preventionTips":["Declare in the schema every field that appears in stored documents and is referenced by arrayFilters","Keep schema definitions in sync with production data (schema drift checks in CI)","Set strictQuery deliberately per query instead of inheriting a global setting blindly"],"tags":["mongoose","array-filters","strict-query","schema","update"],"backgroundTag":"unknown-schema-path","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}