{"record":{"id":"7ba8a26a3df8fe00","repo":"payloadcms/payload","slug":"field-args-field-was-not-found-in-the-collectio","errorCode":null,"errorMessage":"Field ${args.field} was not found in the collection ${collectionConfig.slug}","messagePattern":"Field (.+?) was not found in the collection (.+?)","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"warning","filePath":"packages/payload/src/collections/operations/findDistinct.ts","lineNumber":127,"sourceCode":"      where: fullWhere,\n    })\n\n    await validateQueryPaths({\n      collectionConfig,\n      overrideAccess: overrideAccess!,\n      req,\n      where: where ?? {},\n    })\n\n    const fieldResult = getFieldByPath({\n      config: payload.config,\n      fields: collectionConfig.flattenedFields,\n      includeRelationships: true,\n      path: args.field,\n    })\n\n    if (!fieldResult) {\n      throw new APIError(\n        `Field ${args.field} was not found in the collection ${collectionConfig.slug}`,\n        httpStatus.BAD_REQUEST,\n      )\n    }\n\n    if (fieldResult.field.hidden && !showHiddenFields) {\n      throw new Forbidden(req.t)\n    }\n\n    if (fieldResult.field.access?.read) {\n      const hasAccess = await fieldResult.field.access.read({\n        collection: collectionConfig,\n        req,\n      })\n      if (!hasAccess) {\n        throw new Forbidden(req.t)\n      }\n    }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/findDistinct.ts#L109-L145","documentation":"In `findDistinctOperation`, `getFieldByPath` resolves the requested `field` against the collection's flattened fields; if it returns null, the field does not exist (or its path doesn't resolve), so an `APIError` (400) is thrown.","triggerScenarios":"`findDistinct` (or `/distinct?field=foo`) where `foo` is not a defined field on the collection, is misspelled, or is a dotted relationship path that does not resolve.","commonSituations":"Typo in the field name; field renamed in a config change; querying a relationship sub-field with the wrong path; field exists only on a different collection.","solutions":["Use a field name that exists on the collection.","For nested/relationship fields, use the correct dotted path that `getFieldByPath` can resolve."],"exampleFix":"// before\nawait payload.findDistinct({ collection: 'posts', field: 'cat' })\n// after\nawait payload.findDistinct({ collection: 'posts', field: 'category' })","handlingStrategy":"validation","validationCode":"function fieldExists(collectionConfig, field) {\n  return collectionConfig.flattenedFields.some(f => f.name === field || field.startsWith(f.name + '.'))\n}","typeGuard":"function isValidField(cfg, field): boolean {\n  return !!getFieldByPath({ fields: cfg.flattenedFields, path: field })\n}","tryCatchPattern":null,"preventionTips":["Validate field names against the collection schema before distinct.","Build distinct calls from known field lists."],"tags":["distinct","validation","field"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}