{"record":{"id":"7bc3d79c7d88737f","repo":"payloadcms/payload","slug":"join-model-was-not-found-for-collectionconfig-sl","errorCode":null,"errorMessage":"Join Model was not found for ${collectionConfig.slug}","messagePattern":"Join Model was not found for (.+?)","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/db-mongodb/src/utilities/buildJoinAggregation.ts","lineNumber":295,"sourceCode":"\n      if (!collectionConfig) {\n        throw new APIError(\n          `Collection config for ${join.field.collection.toString()} was not found`,\n        )\n      }\n\n      let JoinModel: CollectionModel | undefined\n\n      const useDrafts = (draftsEnabled || versions) && hasDraftsEnabled(collectionConfig)\n\n      if (useDrafts) {\n        JoinModel = adapter.versions[collectionConfig.slug]\n      } else {\n        JoinModel = adapter.collections[collectionConfig.slug]\n      }\n\n      if (!JoinModel) {\n        throw new APIError(`Join Model was not found for ${collectionConfig.slug}`)\n      }\n\n      const {\n        count,\n        limit: limitJoin = join.field.defaultLimit ?? 10,\n        page,\n        sort: sortJoin = join.field.defaultSort || collectionConfig.defaultSort,\n        where: whereJoin = {},\n      } = joins?.[join.joinPath] || {}\n\n      if (Array.isArray(join.field.collection)) {\n        throw new Error('Unreachable')\n      }\n\n      const fields = useDrafts\n        ? buildVersionCollectionFields(adapter.payload.config, collectionConfig, true)\n        : collectionConfig.flattenedFields\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/utilities/buildJoinAggregation.ts#L277-L313","documentation":"Thrown when the join target collection's Mongoose model can't be resolved — neither `adapter.versions[collectionConfig.slug]` (drafts path) nor `adapter.collections[collectionConfig.slug]` exist. The collection config exists but its DB model was not built/registered by the adapter.","triggerScenarios":"The join target collection is registered in config but its Mongoose model was never constructed during adapter init (model build failed or was skipped), or a query runs before models are built.","commonSituations":"Init ordering/race; an earlier model-build error for that collection was swallowed; drafts/versions flag inconsistency between config and the models actually built; partial init after a thrown error.","solutions":["Await `payload.init()` fully before issuing join queries.","Inspect startup logs for model-build errors on the named collection.","Verify `versions`/`draftsAndPublish` config is consistent and valid.","Restart the process to rebuild all models from scratch."],"exampleFix":"// startup swallowed an error\nawait payload.init() // throws clearly if a model fails to build\n// then issue join queries","handlingStrategy":"validation","validationCode":"function assertJoinModel(adapter, slug) {\n  const m = adapter.collections[slug] || adapter.versions[slug]\n  if (!m) throw new Error(`No Mongoose model built for ${slug}`)\n  return m\n}","typeGuard":"const hasJoinModel = (adapter, slug) =>\n  Boolean(adapter.collections[slug] || adapter.versions[slug])","tryCatchPattern":"try { await payload.find({ collection, joins }) }\ncatch (e) { if (/Join Model was not found/.test(e.message)) await restartOrWaitInit() else throw e }","preventionTips":["Surface init errors rather than swallowing them.","Await payload.init() before join queries.","Verify versions/drafts config so the correct model branch is built."],"tags":["mongodb","joins","models","init"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}