{"record":{"id":"59e75dfe1f782292","repo":"payloadcms/payload","slug":"collection-with-the-slug-globalslug-was-not-fou","errorCode":null,"errorMessage":"Collection with the slug ${globalSlug} was not found","messagePattern":"Collection with the slug (.+?) was not found","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/queries/getBuildQueryPlugin.ts","lineNumber":52,"sourceCode":"      let fields: FlattenedField[] | null = null\n\n      if (versionsFields) {\n        fields = versionsFields\n      } else {\n        if (globalSlug) {\n          const globalConfig = payload.globals.config.find(({ slug }) => slug === globalSlug)\n\n          if (!globalConfig) {\n            throw new APIError(`Global with the slug ${globalSlug} was not found`)\n          }\n\n          fields = globalConfig.flattenedFields\n        }\n        if (collectionSlug) {\n          const collectionConfig = payload.collections[collectionSlug]?.config\n\n          if (!collectionConfig) {\n            throw new APIError(`Collection with the slug ${globalSlug} was not found`)\n          }\n\n          fields = collectionConfig.flattenedFields\n        }\n      }\n\n      if (fields === null) {\n        throw new APIError('Fields are not initialized.')\n      }\n\n      const result = await parseParams({\n        collectionSlug,\n        fields,\n        globalSlug,\n        locale,\n        parentIsLocalized: false,\n        payload,\n        where,","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/queries/getBuildQueryPlugin.ts#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait payload.find({ collection: 'Posts-typo', where: {...} })\n// after\nif (!payload.collections['Posts']) throw new Error('Unknown collection')\nawait payload.find({ collection: 'Posts', where: {...} })","handlingStrategy":"validation","validationCode":"function assertCollection(payload, slug) {\n  if (!payload.collections[slug]) throw new Error(`Unknown collection slug: ${slug}`)\n  return payload.collections[slug]\n}","typeGuard":"const isRegisteredCollectionSlug = (payload, s) =>\n  typeof s === 'string' && Object.prototype.hasOwnProperty.call(payload.collections, s)","tryCatchPattern":"try { await payload.find({ collection: slug, ... }) }\ncatch (e) { if (/Collection with the slug .* was not found/.test(e.message)) handleUnknownCollection(slug) else throw e }","preventionTips":["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."],"tags":["mongodb","config","collections","slug","bug","query"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}