payloadcms/payload · error · APIError
ERROR: Failed to retrieve collection with the slug "${collec
Error message
ERROR: Failed to retrieve collection with the slug "${collectionSlug}". Does not exist. What it means
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.
Source
Thrown at packages/db-mongodb/src/utilities/getEntity.ts:25
export const getCollection = ({
adapter,
collectionSlug,
versions = false,
}: {
adapter: MongooseAdapter
collectionSlug: string
versions?: boolean
}): {
collectionConfig: SanitizedCollectionConfig
customIDType: Collection['customIDType']
Model: CollectionModel
} => {
const collection = adapter.payload.collections[collectionSlug]
if (!collection) {
throw new APIError(
`ERROR: Failed to retrieve collection with the slug "${collectionSlug}". Does not exist.`,
)
}
if (versions) {
const Model = adapter.versions[collectionSlug]
if (!Model) {
throw new APIError(
`ERROR: Failed to retrieve collection version model with the slug "${collectionSlug}". Does not exist.`,
)
}
return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }
}
const Model = adapter.collections[collectionSlug]
View on GitHub (pinned to 00c58b35c0)
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.
Example fix
// before
await payload.findByID({ collection: 'post', id })
// after
await payload.findByID({ collection: 'posts', id }) Defensive patterns
Strategy: validation
Validate before calling
function assertCollectionExists(payload, slug) {
if (!payload.collections[slug]) throw new Error(`Collection not registered: ${slug}`)
} Type guard
const isRegisteredCollection = (payload, s) => typeof s === 'string' && Object.prototype.hasOwnProperty.call(payload.collections, s)
Try / catch
try { await payload.find({ collection: slug, ... }) }
catch (e) { if (/Failed to retrieve collection with the slug/.test(e.message)) handleUnknownCollection(slug) else throw e } Prevention
- Maintain slug constants shared between config and callers.
- Await payload.init() before any operation.
- Validate dynamic slugs against payload.collections keys.
When it happens
Trigger: Any Mongo adapter operation (find, findOne, create, update, delete, count, etc.) with a `collectionSlug` that is not a key of `payload.collections`.
Common situations: Slug typo; collection renamed without migrating callers; wrong/multi config loaded; querying before init resolves; REST request to a wrong endpoint path.
Related errors
- Collection with the slug ${globalSlug} was not found
- Global with the slug ${globalSlug} was not found
- Collection config for ${join.field.collection.toString()} wa
- Assertion for DB name of ${name} ${slug} was failed.
- ERROR: Failed to retrieve collection version model with the
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/f1d33ed0d2491f60.
Report an issue: GitHub.