{"record":{"id":"230ac7310b01ae31","repo":"payloadcms/payload","slug":"could-not-retrieve-sanitized-join-config-for-col","errorCode":null,"errorMessage":"Could not retrieve sanitized join config for ${collection}.","messagePattern":"Could not retrieve sanitized join config for (.+?)\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/buildJoinAggregation.ts","lineNumber":61,"sourceCode":"  locale,\n  projection,\n  versions,\n}: BuildJoinAggregationArgs): Promise<PipelineStage[]> => {\n  if (!adapter.useJoinAggregations) {\n    return []\n  }\n  if (\n    (Object.keys(collectionConfig.joins).length === 0 &&\n      collectionConfig.polymorphicJoins.length == 0) ||\n    joins === false\n  ) {\n    return []\n  }\n\n  const joinConfig = adapter.payload.collections[collection]?.config?.joins\n\n  if (!joinConfig) {\n    throw new APIError(`Could not retrieve sanitized join config for ${collection}.`)\n  }\n\n  const aggregate: PipelineStage[] = []\n  const polymorphicJoinsConfig = adapter.payload.collections[collection]?.config?.polymorphicJoins\n\n  if (!polymorphicJoinsConfig) {\n    throw new APIError(`Could not retrieve sanitized polymorphic joins config for ${collection}.`)\n  }\n\n  for (const join of polymorphicJoinsConfig) {\n    if (projection && !projection[join.joinPath]) {\n      continue\n    }\n\n    if (joins?.[join.joinPath] === false) {\n      continue\n    }\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/buildJoinAggregation.ts#L43-L79","documentation":"Thrown by `buildJoinAggregation` after it has confirmed the raw `collectionConfig.joins` is non-empty, but then fails to read the sanitized join config at `adapter.payload.collections[collection]?.config?.joins`. The sanitized (runtime) config is produced during init; its absence means the collection was not fully sanitized/registered under that slug.","triggerScenarios":"A query requesting joins on a collection whose sanitized runtime config is missing the `joins` field — slug mismatch between the request and `adapter.payload.collections`, joins stripped during sanitization, or a query issued mid-init before sanitization completed.","commonSituations":"Collection renamed so the request slug no longer matches the registered key; a join definition failed validation and was dropped during sanitization; querying during init; duplicate slug registration shadowing the real config; casing/whitespace mismatch in the slug.","solutions":["Verify the `collection` slug exactly matches a key in `adapter.payload.collections`.","Ensure join definitions are valid so they survive sanitization.","Await `payload.init()` before querying.","Check for duplicate slug registrations that overwrite the sanitized entry."],"exampleFix":"// before\nawait payload.find({ collection: 'posts', joins: { author: {} } }) // 'posts' not registered\n// after\nawait payload.find({ collection: 'Posts', joins: { author: {} } })","handlingStrategy":"validation","validationCode":"function assertJoinConfig(payload, collection) {\n  const cfg = payload.collections[collection]?.config?.joins\n  if (!cfg) throw new Error(`No sanitized join config for ${collection}`)\n  return cfg\n}","typeGuard":"const hasSanitizedJoins = (payload, c) =>\n  Boolean(payload.collections[c]?.config?.joins)","tryCatchPattern":"try { await payload.find({ collection, joins: {...} }) }\ncatch (e) { if (/sanitized join config/.test(e.message)) handleBadJoinTarget(collection) else throw e }","preventionTips":["Verify the collection slug matches the registered key exactly.","Await init before join queries.","Avoid duplicate slug registrations that shadow sanitized config."],"tags":["mongodb","joins","config","sanitization"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}