payloadcms/payload · error · APIError
Collection with the slug ${globalSlug} was not found
Error message
Collection with the slug ${globalSlug} was not found What it means
Thrown by the MongoDB query builder when it needs a collection's field schema to translate a `where` clause, but `payload.collections[collectionSlug]?.config` is undefined. IMPORTANT: the message has a copy-paste bug — it interpolates `${globalSlug}` (which may be undefined or a different value) instead of `collectionSlug`. The failing lookup is actually for `collectionSlug`, so do not trust the slug shown in the message.
Source
Thrown at packages/db-mongodb/src/queries/getBuildQueryPlugin.ts:52
let fields: FlattenedField[] | null = null
if (versionsFields) {
fields = versionsFields
} else {
if (globalSlug) {
const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)
if (!globalConfig) {
throw new APIError(`Global with the slug ${globalSlug} was not found`)
}
fields = globalConfig.flattenedFields
}
if (collectionSlug) {
const collectionConfig = payload.collections[collectionSlug]?.config
if (!collectionConfig) {
throw new APIError(`Collection with the slug ${globalSlug} was not found`)
}
fields = collectionConfig.flattenedFields
}
}
if (fields === null) {
throw new APIError('Fields are not initialized.')
}
const result = await parseParams({
collectionSlug,
fields,
globalSlug,
locale,
parentIsLocalized: false,
payload,
where,View on GitHub (pinned to 00c58b35c0)
Solutions
- Ignore the `globalSlug` text in the message — check the actual `collectionSlug` your code passed.
- Verify the slug equals the `slug` field of a collection in `payload.config.collections`.
- Confirm the collection is registered and `payload.init()` has resolved.
- For dynamic slugs, validate against `Object.keys(payload.collections)` first.
Example fix
// before
await payload.find({ collection: 'Posts-typo', where: {...} })
// after
if (!payload.collections['Posts']) throw new Error('Unknown collection')
await payload.find({ collection: 'Posts', where: {...} }) Defensive patterns
Strategy: validation
Validate before calling
function assertCollection(payload, slug) {
if (!payload.collections[slug]) throw new Error(`Unknown collection slug: ${slug}`)
return payload.collections[slug]
} Type guard
const isRegisteredCollectionSlug = (payload, s) => typeof s === 'string' && Object.prototype.hasOwnProperty.call(payload.collections, s)
Try / catch
try { await payload.find({ collection: slug, ... }) }
catch (e) { if (/Collection with the slug .* was not found/.test(e.message)) handleUnknownCollection(slug) else throw e } Prevention
- Remember the message interpolates the wrong variable — trust your collectionSlug, not the message text.
- Validate dynamic slugs against Object.keys(payload.collections).
- Keep a single source of truth for collection slug constants.
When it happens
Trigger: A query (find/count/etc.) routed through buildQueryPlugin with a `collectionSlug` that is not a key of `payload.collections` — typo, renamed collection, collection defined in a config that isn't loaded, or a query issued before init completes.
Common situations: Renaming a collection without migrating callers; mismatched slug between code and config; multi-config/multi-tenant setups loading the wrong config; REST path segment typo; pre-init queries.
Related errors
- Global with the slug ${globalSlug} was not found
- ERROR: Failed to retrieve collection with the slug "${collec
- Fields are not initialized.
- Collection config for ${join.field.collection.toString()} wa
- Assertion for DB name of ${name} ${slug} was failed.
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/59e75dfe1f782292.
Report an issue: GitHub.