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. Update Operation.

What it means

Thrown by the Local API `update` wrapper in packages/payload/src/collections/operations/local/update.ts:247 when `payload.update({ collection, where, data })` (many-doc form) or the single-doc form references a slug not in `payload.collections`. Defaults to HTTP 500. Fires before transaction setup, so no partial writes occur.

Source

Thrown at packages/payload/src/collections/operations/local/update.ts:247

    filePath,
    limit,
    overrideAccess = true,
    overrideLock,
    overwriteExistingFiles = false,
    populate,
    publishAllLocales,
    select,
    showHiddenFields,
    sort,
    trash = false,
    unpublishAllLocales,
    where,
  } = options

  const collection = payload.collections[collectionSlug]

  if (!collection) {
    throw new APIError(
      `The collection with slug ${String(collectionSlug)} can't be found. Update Operation.`,
    )
  }

  const req = await createLocalReq(options as CreateLocalReqOptions, payload)
  req.file = file ?? (await getFileByPath(filePath!))

  const args = {
    id,
    autosave,
    collection,
    data,
    depth,
    disableTransaction,
    draft,
    limit,
    overrideAccess,
    overrideLock,

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Match the slug to the collection config's `slug` value exactly.
  2. Validate dynamic slugs against `Object.keys(payload.collections)` before updating.
  3. Ensure `payload.init()` resolved.
  4. Remove `as CollectionSlug` casts so the compiler rejects unknown slugs.

Example fix

// before
await payload.update({ collection: 'post', where: { id: { equals: id } }, data }) // slug is 'posts'

// after
await payload.update({ collection: 'posts', where: { id: { equals: id } }, data })
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, 'posts')
await payload.update({ collection: 'posts', where, data })

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.update({ collection: slug, where, data })
}

Try / catch

try {
  await payload.update({ collection: slug, where, data })
} catch (err) {
  if (err instanceof APIError && /Update Operation/.test(err.message)) {
    // unknown slug — correct it (note: also matches 'Restore Version'? no — different wording)
  } else throw err
}

Prevention

When it happens

Trigger: Calling `payload.update({ collection: 'post', where: {...}, data })` with a typo (real slug `'posts'`); updating via a generic service that receives a slug from config that is out of sync; calling update before `payload.init()`.

Common situations: Slug typo or stale constant; collection renamed/removed; plugin not loaded; `as CollectionSlug` cast on dynamic input.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/f8622455039bb2c8. Report an issue: GitHub.