{"record":{"id":"3a9107d5bd483f93","repo":"withastro/astro","slug":"the-collection-json-stringify-collection-does","errorCode":null,"errorMessage":"The collection ${JSON.stringify(collection)} does not exist or is empty. Please check your content config file for errors.","messagePattern":"The collection (.+?) does not exist or is empty\\. Please check your content config file for errors\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/astro/src/content/runtime.ts","lineNumber":136,"sourceCode":"\n\t\t\tconst result = [];\n\t\t\tfor (const rawEntry of await store.values<DataEntry>(collection)) {\n\t\t\t\tconst data = resolveEntryData(rawEntry, imageAssetMap);\n\n\t\t\t\tlet entry = {\n\t\t\t\t\t...rawEntry,\n\t\t\t\t\tdata,\n\t\t\t\t\tcollection,\n\t\t\t\t};\n\n\t\t\t\tif (hasFilter && !filter(entry)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tresult.push(entry);\n\t\t\t}\n\t\t\treturn result;\n\t\t} else {\n\t\t\tlogger.warn(\n\t\t\t\t'content',\n\t\t\t\t`The collection ${JSON.stringify(\n\t\t\t\t\tcollection,\n\t\t\t\t)} does not exist or is empty. Please check your content config file for errors.`,\n\t\t\t);\n\t\t\treturn [];\n\t\t}\n\t};\n}\n\ntype ContentEntryResult = {\n\tid: string;\n\tslug: string;\n\tbody: string;\n\tcollection: string;\n\tdata: Record<string, any>;\n\tdigest?: string | number;\n\trender(): Promise<RenderResult>;","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/content/runtime.ts#L118-L154","documentation":"getCollection(name) was called at runtime for a collection the data store does not contain; Astro logs this warning and returns an empty array. It fires when the name does not match a key in the content config (typo, rename) or when the collection's loader loaded zero entries or failed to run at all.","triggerScenarios":"getCollection('blog') when the config defines 'posts'; the content config file failing to load so no collections register; the collection's loader erroring (bad base dir, zero glob matches — each has its own warning) leaving the store empty for that name.","commonSituations":"Renaming collections without updating queries; collection names built dynamically from URL parameters; migrating from legacy src/content/config.ts to the Content Layer where definitions moved.","solutions":["Check the exact collection key in the defineCollection call in the content config and use it verbatim","Scan dev-server/build logs for loader errors (missing directory, no matches, no entry type) that left the collection empty","Run astro sync or restart the dev server so the store regenerates","Guard rendering code against an empty array so pages degrade gracefully"],"exampleFix":"// before\nconst posts = await getCollection('blog'); // config defines 'posts'\n\n// after\nconst posts = await getCollection('posts');","handlingStrategy":"type-guard","validationCode":"// Fail at compile time on unknown collection names using generated types\nimport type { CollectionKey } from 'astro:content';\nconst VALID_COLLECTIONS = ['blog', 'authors', 'tags'] as const satisfies readonly CollectionKey[];\nfunction assertCollection(name: string): asserts name is CollectionKey {\n  if (!VALID_COLLECTIONS.includes(name as never)) {\n    throw new Error(`Unknown collection \"${name}\" — check src/content.config.ts`);\n  }\n}","typeGuard":"import type { CollectionKey } from 'astro:content';\nconst KNOWN: readonly string[] = ['blog', 'authors', 'tags'];\nfunction isKnownCollection(name: string): name is CollectionKey {\n  return (KNOWN as readonly string[]).includes(name);\n}","tryCatchPattern":null,"preventionTips":["Run astro sync after editing collection definitions so generated types stay current","Never build collection names from unvalidated URL params; whitelist them","Watch loader logs — an empty collection is usually an earlier loader warning (bad base, zero matches)"],"tags":["astro","content-collections","get-collection","empty-result","runtime"],"backgroundTag":"missing-content-collection","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-09-09T03:35:40.650Z","contentChangedAt":"2026-09-09T03:35:40.650Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}