{"record":{"id":"4b23e08ff985b1bf","repo":"payloadcms/payload","slug":"the-collection-with-slug-string-collectionslug-4b23e0","errorCode":null,"errorMessage":"The collection with slug ${String(collectionSlug)} can't be found. Count Versions Operation.","messagePattern":"The collection with slug (.+?) can't be found\\. Count Versions Operation\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/collections/operations/local/countVersions.ts","lineNumber":59,"sourceCode":"   * If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.\n   */\n  user?: null | User\n  /**\n   * A filter [query](https://payloadcms.com/docs/queries/overview)\n   */\n  where?: Where\n}\n\nexport async function countVersionsLocal<TSlug extends CollectionSlug>(\n  payload: Payload,\n  options: CountVersionsOptions<TSlug>,\n): Promise<{ totalDocs: number }> {\n  const { collection: collectionSlug, disableErrors, overrideAccess = true, where } = options\n\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. Count Versions Operation.`,\n    )\n  }\n\n  return countVersionsOperation<TSlug>({\n    collection,\n    disableErrors,\n    overrideAccess,\n    req: await createLocalReq(options as CreateLocalReqOptions, payload),\n    where,\n  })\n}\n","sourceCodeStart":41,"sourceCodeEnd":72,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/local/countVersions.ts#L41-L72","documentation":"Thrown by the Local API `countVersions` wrapper in packages/payload/src/collections/operations/local/countVersions.ts:59 when the `collection` slug supplied to `payload.countVersions(...)` is not present in `payload.collections`. It defaults to HTTP 500 since no status is passed. This only matters for collections with drafts/versions enabled.","triggerScenarios":"Calling `payload.countVersions({ collection: 'post' })` against a misspelled slug, or counting versions of a collection whose `versions` config was disabled (so the slug may still be valid but no versions table exists), or using a slug from an older config after a rename.","commonSituations":"Renaming a versioned collection without updating the analytics/dashboard code that counts versions; calling countVersions in a migration before the collection is registered; asserting a dynamic slug with `as CollectionSlug`.","solutions":["Confirm the slug matches the collection config's `slug` property exactly (watch singular/plural).","Verify `versions: true` (or a drafts config) is set on that collection, since countVersions only applies to versioned collections.","Print `Object.keys(payload.collections)` to verify the slug is registered at call time.","Drop `as CollectionSlug` casts on runtime-built strings."],"exampleFix":"// before\nawait payload.countVersions({ collection: 'page' }) // real slug is 'pages'\n\n// after\nawait payload.countVersions({ collection: 'pages' })","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, 'pages')\nawait payload.countVersions({ collection: 'pages' })","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.countVersions({ collection: slug })\n}","tryCatchPattern":"try {\n  await payload.countVersions({ collection: slug })\n} catch (err) {\n  if (err instanceof APIError && /Count Versions Operation/.test(err.message)) {\n    // unknown slug — log registered slugs and fix caller\n  } else throw err\n}","preventionTips":["Keep a single source of truth for collection slug constants.","Confirm versions are enabled on the target collection.","Avoid `as CollectionSlug` casts on runtime-built strings."],"tags":["local-api","collection","slug","versions","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}