payloadcms/payload · error · APIError
The collection with slug ${String(collectionSlug)} can't be
Error message
The collection with slug ${String(collectionSlug)} can't be found. Find Operation. What it means
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.
Source
Thrown at packages/payload/src/collections/operations/local/findDistinct.ts:129
): Promise<PaginatedDistinctDocs<Record<TField, DataFromCollectionSlug<TSlug>[TField]>>> {
const {
collection: collectionSlug,
depth = 0,
disableErrors,
field,
limit,
overrideAccess = true,
page,
populate,
showHiddenFields,
sort,
trash = false,
where,
} = options
const collection = payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`The collection with slug ${String(collectionSlug)} can't be found. Find Operation.`,
)
}
return findDistinctOperation({
collection,
depth,
disableErrors,
field,
limit,
overrideAccess,
page,
populate,
req: await createLocalReq(options as CreateLocalReqOptions, payload),
showHiddenFields,
sort,
trash,
where,View on GitHub (pinned to 00c58b35c0)
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.
Example fix
// before
await payload.findDistinct({ collection: 'tag', field: 'name' }) // slug is 'tags'
// after
await payload.findDistinct({ collection: 'tags', field: 'name' }) Defensive patterns
Strategy: validation
Validate before calling
function assertCollectionSlug(payload: Payload, slug: string): void {
if (!(slug in payload.collections)) {
throw new Error(`Unknown collection slug '${slug}'`)
}
}
assertCollectionSlug(payload, 'tags')
await payload.findDistinct({ collection: 'tags', field: 'name' }) Type guard
const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>
slug in (payload.collections as Record<string, unknown>)
if (slugIsRegistered(payload, slug)) {
await payload.findDistinct({ collection: slug, field: 'name' })
} Try / catch
try {
await payload.findDistinct({ collection: slug, field })
} catch (err) {
// NOTE: message says 'Find Operation.' not 'Find Distinct'
if (err instanceof APIError && /Find Operation/.test(err.message) && field) {
// likely unknown slug — verify against payload.collections
} else throw err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Slug typo; collection renamed; plugin not loaded; `as CollectionSlug` cast on a dynamic slug.
Related errors
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
- The collection with slug ${String(collectionSlug)} can't be
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/7246ccf083ec5e3e.
Report an issue: GitHub.