{"record":{"id":"02514db28e03f5ba","repo":"payloadcms/payload","slug":"collection-with-the-slug-collectionslug-was-not","errorCode":null,"errorMessage":"Collection with the slug ${collectionSlug} 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/buildSearchParams.ts","lineNumber":138,"sourceCode":"\n    if (!formattedOperator) {\n      return undefined\n    }\n\n    // If there are multiple collections to search through,\n    // Recursively build up a list of query constraints\n    if (paths.length > 1) {\n      // Remove top collection and reverse array\n      // to work backwards from top\n      const pathsToQuery = paths.slice(1).reverse()\n\n      let relationshipQuery: SearchParam = {\n        value: {},\n      }\n\n      for (const [i, { collectionSlug, path: subPath }] of pathsToQuery.entries()) {\n        if (!collectionSlug) {\n          throw new APIError(`Collection with the slug ${collectionSlug} was not found.`)\n        }\n\n        const { collectionConfig, Model: SubModel } = getCollection({\n          adapter: payload.db as MongooseAdapter,\n          collectionSlug,\n        })\n\n        if (i === 0) {\n          const subQuery = await SubModel.buildQuery({\n            locale,\n            payload,\n            where: {\n              [subPath]: {\n                [formattedOperator]: val,\n              },\n            },\n          })\n","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/db-mongodb/src/queries/buildSearchParams.ts#L120-L156","documentation":"During nested relationship query building, buildSearchParam iterates the reversed path list and throws an APIError when a path entry has no collectionSlug. Note the message is misleading: it fires precisely when collectionSlug is undefined (so the message reads 'Collection with the slug undefined was not found'), not when a slug is unknown.","triggerScenarios":"A multi-hop where/relationship query (path traverses >1 collection) where one hop's PathToQuery entry lacks a collectionSlug — e.g. a relationship/join field whose relationTo could not be resolved, or a malformed deeply-nested query path.","commonSituations":"Querying a nested relationship path where an intermediate field is not a relationship (so no target collection); config drift where a relationship field was changed to another type; a join field whose `on` references a non-relationship field.","solutions":["Simplify the query path and confirm each segment is a relationship/upload/join with a resolvable target collection.","Inspect the field config for the path; ensure relationTo is set and the target collection exists.","Avoid querying through fields that are not relationships (arrays/blocks/groups do not carry a collectionSlug hop).","Check payload.config for the queried collection/field to confirm the relationship chain is intact."],"exampleFix":"// before — querying through a non-relationship segment\nawait payload.find({\n  collection: 'orders',\n  where: { 'customer.address.someField': { equals: 'x' } }, // address is a group, not a relation\n})\n\n// after — query only through relationship segments\nawait payload.find({\n  collection: 'orders',\n  where: { 'customer.name': { equals: 'x' } }, // customer is a relationship\n})","handlingStrategy":"validation","validationCode":"// Validate each segment of a nested query path is a relationship before querying\nimport { getFieldByPath } from 'payload'\n\nfunction assertPathIsRelational(fields: any[], path: string) {\n  const segments = path.split('.')\n  let currentFields = fields\n  for (const seg of segments.slice(0, -1)) {\n    const f = getFieldByPath({ fields: currentFields, path: seg })\n    if (!f || (f.type !== 'relationship' && f.type !== 'upload' && f.type !== 'join')) {\n      throw new Error(`Path segment '${seg}' is not relational — cannot nest query through it`)\n    }\n  }\n}","typeGuard":"function isRelationalField(f: unknown): f is { type: 'relationship' | 'upload' | 'join' } {\n  return typeof f === 'object' && f !== null &&\n    ['relationship', 'upload', 'join'].includes((f as any).type)\n}","tryCatchPattern":"try {\n  await payload.find({ collection: 'orders', where: { 'customer.name': { equals: 'x' } } })\n} catch (e) {\n  if (e instanceof APIError && /Collection with the slug .* was not found/.test(e.message)) {\n    console.error('Query path traverses a non-relational segment — simplify the where clause')\n  }\n  throw e\n}","preventionTips":["Only chain where-clause paths through relationship/upload/join fields.","Verify the relationship chain in config before issuing nested queries.","Re-validate field config after renames or type changes."],"tags":["db-mongodb","query","relationship","api-error"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}