payloadcms/payload · error · APIError
ERROR: Failed to retrieve collection model with the slug "${
Error message
ERROR: Failed to retrieve collection model with the slug "${collectionSlug}". Does not exist. What it means
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.
Source
Thrown at packages/db-mongodb/src/utilities/getEntity.ts:45
)
}
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]
if (!Model) {
throw new APIError(
`ERROR: Failed to retrieve collection model with the slug "${collectionSlug}". Does not exist.`,
)
}
return { collectionConfig: collection.config, customIDType: collection.customIDType, Model }
}
type BaseGetGlobalArgs = {
adapter: MongooseAdapter
globalSlug: string
}
interface GetGlobal {
(args: { versions?: false | undefined } & BaseGetGlobalArgs): {
globalConfig: SanitizedGlobalConfig
Model: GlobalModel
}
(args: { versions?: true } & BaseGetGlobalArgs): {View on GitHub (pinned to 00c58b35c0)
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.
Example fix
// before
const payload = await payload.init() // error swallowed
await payload.find({ collection: 'posts' })
// after
try { await payload.init() } catch (e) { /* surface init errors */ } Defensive patterns
Strategy: validation
Validate before calling
function assertCollectionModel(adapter, slug) {
if (!adapter.collections[slug]) throw new Error(`No Mongoose model for ${slug}`)
} Type guard
const hasCollectionModel = (adapter, s) => Boolean(adapter.collections[s])
Try / catch
try { await payload.find({ collection: slug }) }
catch (e) { if (/collection model with the slug/.test(e.message)) await ensureInit(payload) else throw e } Prevention
- Await payload.init() and surface any init errors.
- Avoid duplicate collection slugs that cause model overwrites.
- Restart to rebuild models after config changes.
When it happens
Trigger: A standard (non-versions) operation on a collection whose model wasn't constructed during adapter init, or a query issued before models are built.
Common situations: 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.
Related errors
- Join Model was not found for ${collectionConfig.slug}
- Collection with the slug ${globalSlug} was not found
- Collection config for ${join.field.collection.toString()} wa
- ERROR: Failed to retrieve collection with the slug "${collec
- ERROR: Failed to retrieve collection version model with the
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/e1b54894170ae633.
Report an issue: GitHub.