{"record":{"id":"d90d02e8f8020495","repo":"payloadcms/payload","slug":"global-with-the-slug-globalslug-was-not-found","errorCode":null,"errorMessage":"Global with the slug ${globalSlug} was not found","messagePattern":"Global with the slug (.+?) was not found","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/queries/getBuildQueryPlugin.ts","lineNumber":43,"sourceCode":"}: GetBuildQueryPluginArgs = {}) => {\n  return function buildQueryPlugin(schema: any) {\n    const modifiedSchema = schema\n    async function schemaBuildQuery({\n      globalSlug,\n      locale,\n      payload,\n      where,\n    }: BuildQueryArgs): Promise<Record<string, unknown>> {\n      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      }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/queries/getBuildQueryPlugin.ts#L25-L61","documentation":"Thrown by the MongoDB adapter's query builder (getBuildQueryPlugin) when it must resolve a global's flattened field schema to translate a Payload `where` clause into a MongoDB aggregation/filter, but `payload.globals.config.find()` returns no match for the supplied `globalSlug`. Without field definitions the param parser cannot coerce or validate query values, so the adapter aborts rather than emit a silently-wrong query.","triggerScenarios":"Any query path that routes through buildQueryPlugin with a `globalSlug` not present in `payload.config.globals` — e.g. `req.payload.db.collections[slug]` queries, internal global queries with a `where` param, or a REST/global operation that supplies a slug not registered during init.","commonSituations":"Renaming a global without updating callers; slug typo; loading the wrong Payload config in a multi-tenant setup; issuing queries before `payload.init()` has finished registering globals; user/dynamic slug input that is not validated.","solutions":["Verify the `globalSlug` string exactly equals the `slug` property of a global in your `globals` config array.","Confirm the global is actually passed to `payload.init({ globals: [...] })` (or auto-loaded) and that init has resolved.","If the slug is dynamic/user-supplied, validate it against `payload.config.globals` before issuing the query.","Check for duplicate or shadowing global configs that change which slug resolves."],"exampleFix":"// before\nawait payload.db.collections['nonexistent-global'].find({ where: {...} })\n// after\nconst exists = payload.config.globals.some(g => g.slug === globalSlug)\nif (!exists) throw new Error(`Unknown global: ${globalSlug}`)\nawait payload.findGlobal({ slug: globalSlug, ... })","handlingStrategy":"validation","validationCode":"function resolveGlobalSlug(payload, globalSlug) {\n  const g = payload.config.globals.find(x => x.slug === globalSlug)\n  if (!g) throw new Error(`Unknown global slug: ${globalSlug}`)\n  return g\n}","typeGuard":"const isRegisteredGlobalSlug = (payload, s) =>\n  typeof s === 'string' && payload.config.globals.some(g => g.slug === s)","tryCatchPattern":"try { await payload.findGlobal({ slug, ... }) }\ncatch (e) { if (/Global with the slug .* was not found/.test(e.message)) handleUnknownGlobal(slug) else throw e }","preventionTips":["Centralize slug lookups behind a resolver that validates against payload.config.globals.","Never accept raw user input as a global slug without validation.","Await payload.init() before issuing any query."],"tags":["mongodb","config","globals","slug","query"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}