{"record":{"id":"6afc50285b6e5022","repo":"payloadcms/payload","slug":"error-failed-to-retrieve-collection-version-model","errorCode":null,"errorMessage":"ERROR: Failed to retrieve collection version model with the slug \"${collectionSlug}\". Does not exist.","messagePattern":"ERROR: Failed to retrieve collection version model with the slug \"(.+?)\"\\. Does not exist\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/getEntity.ts","lineNumber":34,"sourceCode":"}): {\n  collectionConfig: SanitizedCollectionConfig\n  customIDType: Collection['customIDType']\n\n  Model: CollectionModel\n} => {\n  const collection = adapter.payload.collections[collectionSlug]\n\n  if (!collection) {\n    throw new APIError(\n      `ERROR: Failed to retrieve collection with the slug \"${collectionSlug}\". Does not exist.`,\n    )\n  }\n\n  if (versions) {\n    const Model = adapter.versions[collectionSlug]\n\n    if (!Model) {\n      throw new APIError(\n        `ERROR: Failed to retrieve collection version model with the slug \"${collectionSlug}\". Does not exist.`,\n      )\n    }\n\n    return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }\n  }\n\n  const Model = adapter.collections[collectionSlug]\n\n  if (!Model) {\n    throw new APIError(\n      `ERROR: Failed to retrieve collection model with the slug \"${collectionSlug}\". Does not exist.`,\n    )\n  }\n\n  return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }\n}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/getEntity.ts#L16-L52","documentation":"Thrown by `getEntity` when `versions: true` is requested but `adapter.versions[collectionSlug]` is undefined — the versions Mongoose model was never built. This means versions/drafts are not enabled on that collection, or the model build was skipped/raced.","triggerScenarios":"Calling a versions-aware operation (`findVersions`, `findVersionByID`, `deleteVersion`, `restoreVersion`, etc.) on a collection whose config does not have `versions: true`, or before the versions models were built during init.","commonSituations":"`versions: false` (or omitted) on the collection but the caller requests versions; config changed to enable versions but the process wasn't restarted; init race; drafts config inconsistency.","solutions":["Confirm `versions: true` (and `drafts` config if used) is set on the collection.","Restart the process so versions models are rebuilt.","Await `payload.init()` before calling versions APIs.","If versions are genuinely not enabled, use the non-versions API instead."],"exampleFix":"// before\n{ slug: 'posts', versions: false }\nawait payload.findVersions({ collection: 'posts' })\n// after\n{ slug: 'posts', versions: { drafts: true } }\nawait payload.findVersions({ collection: 'posts' })","handlingStrategy":"validation","validationCode":"function assertVersionsEnabled(payload, slug) {\n  const enabled = payload.collections[slug]?.config?.versions\n  if (!enabled) throw new Error(`Versions not enabled on ${slug}`)\n}","typeGuard":"const hasVersionsEnabled = (payload, s) =>\n  Boolean(payload.collections[s]?.config?.versions)","tryCatchPattern":"try { await payload.findVersions({ collection: slug }) }\ncatch (e) { if (/version model with the slug/.test(e.message)) enableVersionsOrUseBaseApi(slug) else throw e }","preventionTips":["Set versions: true (or drafts) on collections you call versions APIs on.","Restart after enabling versions so models rebuild.","Use the non-versions API when versions aren't enabled."],"tags":["mongodb","versions","collections","config"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}