{"record":{"id":"7246ccf083ec5e3e","repo":"payloadcms/payload","slug":"the-collection-with-slug-string-collectionslug-7246cc","errorCode":null,"errorMessage":"The collection with slug ${String(collectionSlug)} can't be found. Find Operation.","messagePattern":"The collection with slug (.+?) can't be found\\. Find Operation\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/collections/operations/local/findDistinct.ts","lineNumber":129,"sourceCode":"): Promise<PaginatedDistinctDocs<Record<TField, DataFromCollectionSlug<TSlug>[TField]>>> {\n  const {\n    collection: collectionSlug,\n    depth = 0,\n    disableErrors,\n    field,\n    limit,\n    overrideAccess = true,\n    page,\n    populate,\n    showHiddenFields,\n    sort,\n    trash = false,\n    where,\n  } = options\n  const collection = payload.collections[collectionSlug]\n\n  if (!collection) {\n    throw new APIError(\n      `The collection with slug ${String(collectionSlug)} can't be found. Find Operation.`,\n    )\n  }\n\n  return findDistinctOperation({\n    collection,\n    depth,\n    disableErrors,\n    field,\n    limit,\n    overrideAccess,\n    page,\n    populate,\n    req: await createLocalReq(options as CreateLocalReqOptions, payload),\n    showHiddenFields,\n    sort,\n    trash,\n    where,","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/local/findDistinct.ts#L111-L147","documentation":"Thrown by the Local API `findDistinct` wrapper in packages/payload/src/collections/operations/local/findDistinct.ts:129 when `payload.findDistinct({ collection, field })` references a slug absent from `payload.collections`. Defaults to HTTP 500. Note the message text reuses 'Find Operation.' (not 'Find Distinct'), which can mislead debugging.","triggerScenarios":"Calling `payload.findDistinct({ collection: 'tag', field: 'name' })` with a misspelled slug; building a distinct-values endpoint from a config-driven slug that is out of sync; calling before collections are registered.","commonSituations":"Slug typo; collection renamed; plugin not loaded; `as CollectionSlug` cast on a dynamic slug.","solutions":["Match the slug to the collection config exactly.","Validate the slug via `Object.keys(payload.collections)` before the call.","Ensure `payload.init()` completed.","Drop `as CollectionSlug` casts so the literal union catches typos."],"exampleFix":"// before\nawait payload.findDistinct({ collection: 'tag', field: 'name' }) // slug is 'tags'\n\n// after\nawait payload.findDistinct({ collection: 'tags', field: 'name' })","handlingStrategy":"validation","validationCode":"function assertCollectionSlug(payload: Payload, slug: string): void {\n  if (!(slug in payload.collections)) {\n    throw new Error(`Unknown collection slug '${slug}'`)\n  }\n}\nassertCollectionSlug(payload, 'tags')\nawait payload.findDistinct({ collection: 'tags', field: 'name' })","typeGuard":"const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>\n  slug in (payload.collections as Record<string, unknown>)\n\nif (slugIsRegistered(payload, slug)) {\n  await payload.findDistinct({ collection: slug, field: 'name' })\n}","tryCatchPattern":"try {\n  await payload.findDistinct({ collection: slug, field })\n} catch (err) {\n  // NOTE: message says 'Find Operation.' not 'Find Distinct'\n  if (err instanceof APIError && /Find Operation/.test(err.message) && field) {\n    // likely unknown slug — verify against payload.collections\n  } else throw err\n}","preventionTips":["Remember the error message reuses 'Find Operation.' text — match on slug registration, not the exact operation word.","Keep slug constants centralized.","Avoid `as CollectionSlug` casts on dynamic slugs."],"tags":["local-api","collection","slug","find-distinct","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}