{"record":{"id":"e1b54894170ae633","repo":"payloadcms/payload","slug":"error-failed-to-retrieve-collection-model-with-th","errorCode":null,"errorMessage":"ERROR: Failed to retrieve collection model with the slug \"${collectionSlug}\". Does not exist.","messagePattern":"ERROR: Failed to retrieve collection model with the slug \"(.+?)\"\\. Does not exist\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/getEntity.ts","lineNumber":45,"sourceCode":"    )\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\ntype BaseGetGlobalArgs = {\n  adapter: MongooseAdapter\n  globalSlug: string\n}\n\ninterface GetGlobal {\n  (args: { versions?: false | undefined } & BaseGetGlobalArgs): {\n    globalConfig: SanitizedGlobalConfig\n    Model: GlobalModel\n  }\n  (args: { versions?: true } & BaseGetGlobalArgs): {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/getEntity.ts#L27-L63","documentation":"Thrown by `getEntity` (non-versions branch) when `adapter.collections[collectionSlug]` is undefined — the Mongoose model for the collection was never built, even though the collection config resolves. This indicates the model-construction step of init did not complete for that slug.","triggerScenarios":"A standard (non-versions) operation on a collection whose model wasn't constructed during adapter init, or a query issued before models are built.","commonSituations":"Init race (querying before init resolves); an earlier model-build error for that collection was swallowed; partial init after a thrown error; duplicate slug registration causing one model to be overwritten/missing.","solutions":["Await `payload.init()` before querying.","Inspect startup logs for model-build errors on the named collection.","Restart to rebuild all models.","Verify there are no duplicate collection slugs in config."],"exampleFix":"// before\nconst payload = await payload.init() // error swallowed\nawait payload.find({ collection: 'posts' })\n// after\ntry { await payload.init() } catch (e) { /* surface init errors */ }","handlingStrategy":"validation","validationCode":"function assertCollectionModel(adapter, slug) {\n  if (!adapter.collections[slug]) throw new Error(`No Mongoose model for ${slug}`)\n}","typeGuard":"const hasCollectionModel = (adapter, s) => Boolean(adapter.collections[s])","tryCatchPattern":"try { await payload.find({ collection: slug }) }\ncatch (e) { if (/collection model with the slug/.test(e.message)) await ensureInit(payload) else throw e }","preventionTips":["Await payload.init() and surface any init errors.","Avoid duplicate collection slugs that cause model overwrites.","Restart to rebuild models after config changes."],"tags":["mongodb","models","collections","init"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}