{"record":{"id":"33acf7ec762b4153","repo":"payloadcms/payload","slug":"fields-are-not-initialized","errorCode":null,"errorMessage":"Fields are not initialized.","messagePattern":"Fields are not initialized\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/queries/getBuildQueryPlugin.ts","lineNumber":60,"sourceCode":"          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,\n      })\n\n      return result\n    }\n    modifiedSchema.statics.buildQuery = schemaBuildQuery\n  }\n}\n","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/queries/getBuildQueryPlugin.ts#L42-L78","documentation":"Thrown by the MongoDB query builder after the global/collection lookup block when `fields` is still `null` — meaning neither `globalSlug` nor `collectionSlug` was supplied (or both were falsy). The param parser requires field definitions to operate, so it refuses to build a query rather than guess.","triggerScenarios":"`getBuildQueryPlugin` invoked with neither `globalSlug` nor `collectionSlug` set; both passed as undefined/empty string; an internal caller or custom adapter method forgot to forward the originating slug into BuildQueryArgs.","commonSituations":"Custom adapter code or plugin calling the query builder directly without context; a regression after a Payload upgrade that changed the BuildQueryArgs shape; middleware that strips the slug before it reaches the query layer.","solutions":["Ensure every query call specifies either `collectionSlug` or `globalSlug`.","If you call the plugin/adapter internals directly, always forward the originating slug.","Audit middleware/REST layers to confirm the slug is propagated into the query args.","On upgrade, re-check the BuildQueryArgs interface for new required fields."],"exampleFix":"// before\nawait adapter.query({ where, payload }) // no slug\n// after\nawait adapter.query({ collectionSlug: 'Posts', where, payload })","handlingStrategy":"validation","validationCode":"function assertQueryContext(args) {\n  if (!args.collectionSlug && !args.globalSlug)\n    throw new Error('Either collectionSlug or globalSlug is required')\n}","typeGuard":"const hasQueryTarget = (a) => Boolean(a?.collectionSlug) || Boolean(a?.globalSlug)","tryCatchPattern":"try { await adapter.query(args) }\ncatch (e) { if (/Fields are not initialized/.test(e.message)) throw new Error('Query missing collection/global context') else throw e }","preventionTips":["Always pass the originating slug into adapter internals.","After upgrades, re-check BuildQueryArgs for newly required fields.","Type your query args so missing slugs fail at compile time."],"tags":["mongodb","internal","config","query"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}