{"record":{"id":"f1d33ed0d2491f60","repo":"payloadcms/payload","slug":"error-failed-to-retrieve-collection-with-the-slug","errorCode":null,"errorMessage":"ERROR: Failed to retrieve collection with the slug \"${collectionSlug}\". Does not exist.","messagePattern":"ERROR: Failed to retrieve collection with the slug \"(.+?)\"\\. Does not exist\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/getEntity.ts","lineNumber":25,"sourceCode":"\nexport const getCollection = ({\n  adapter,\n  collectionSlug,\n  versions = false,\n}: {\n  adapter: MongooseAdapter\n  collectionSlug: string\n  versions?: boolean\n}): {\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","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/getEntity.ts#L7-L43","documentation":"Thrown by `getEntity` — the central slug→config+model resolver used by nearly every MongoDB adapter operation — when `adapter.payload.collections[collectionSlug]` is undefined. The collection is not registered at runtime, so no config/model lookup can proceed.","triggerScenarios":"Any Mongo adapter operation (find, findOne, create, update, delete, count, etc.) with a `collectionSlug` that is not a key of `payload.collections`.","commonSituations":"Slug typo; collection renamed without migrating callers; wrong/multi config loaded; querying before init resolves; REST request to a wrong endpoint path.","solutions":["Verify the slug exactly matches a `slug` in `payload.config.collections`.","Confirm the collection is registered and `payload.init()` resolved.","For dynamic slugs, validate against `Object.keys(payload.collections)` first.","Check REST route spelling against the configured collection slug."],"exampleFix":"// before\nawait payload.findByID({ collection: 'post', id })\n// after\nawait payload.findByID({ collection: 'posts', id })","handlingStrategy":"validation","validationCode":"function assertCollectionExists(payload, slug) {\n  if (!payload.collections[slug]) throw new Error(`Collection not registered: ${slug}`)\n}","typeGuard":"const isRegisteredCollection = (payload, s) =>\n  typeof s === 'string' && Object.prototype.hasOwnProperty.call(payload.collections, s)","tryCatchPattern":"try { await payload.find({ collection: slug, ... }) }\ncatch (e) { if (/Failed to retrieve collection with the slug/.test(e.message)) handleUnknownCollection(slug) else throw e }","preventionTips":["Maintain slug constants shared between config and callers.","Await payload.init() before any operation.","Validate dynamic slugs against payload.collections keys."],"tags":["mongodb","collections","slug","config"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}