{"record":{"id":"6ee8f1b42bedc55f","repo":"withastro/astro","slug":"unknowncontentcollectionerror","errorCode":"UnknownContentCollectionError","errorMessage":"Collection \"${collection}\" is a live collection. Use getLiveCollection() instead of getCollection().","messagePattern":"Collection \"(.+?)\" is a live collection\\. Use getLiveCollection\\(\\) instead of getCollection\\(\\)\\.","errorType":"error_code","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/content/runtime.ts","lineNumber":107,"sourceCode":"\t\t\t\terror as Error,\n\t\t\t),\n\t\t};\n\t}\n}\n\nexport function createGetCollection({\n\tliveCollections,\n\tlogger,\n}: {\n\tliveCollections: LiveCollectionConfigMap;\n\tlogger: AstroLogger;\n}) {\n\treturn async function getCollection(\n\t\tcollection: string,\n\t\tfilter?: ((entry: any) => unknown) | Record<string, unknown>,\n\t) {\n\t\tif (collection in liveCollections) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.UnknownContentCollectionError,\n\t\t\t\tmessage: `Collection \"${collection}\" is a live collection. Use getLiveCollection() instead of getCollection().`,\n\t\t\t});\n\t\t}\n\n\t\tconst hasFilter = typeof filter === 'function';\n\t\tconst store = await globalDataStore.get();\n\t\tif (await store.hasCollection(collection)) {\n\t\t\t// @ts-expect-error\tvirtual module\n\t\t\tconst { default: imageAssetMap } = await import('astro:asset-imports');\n\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,","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/content/runtime.ts#L89-L125","documentation":"Astro distinguishes persisted content collections from live collections (defined with `defineLiveCollection`, type 'live', fetched at request time). Calling `getCollection()` on a live collection throws this UnknownContentCollectionError variant, steering you to `getLiveCollection()`, because live entries are never in the data store `getCollection()` reads.","triggerScenarios":"`await getCollection('products')` where `products` is defined via `defineLiveCollection({ type: 'live', loader: ... })` in src/content/config.ts (or live.config.ts).","commonSituations":"Converting a collection to the experimental live-collections feature and forgetting to update queries; shared components/utilities that call getCollection for any collection name passed in; upgrading Astro versions where a collection changed to live.","solutions":["Switch the call to `getLiveCollection('products')` (entries expose `data` and live-specific fields; no `render()`).","If the collection should be build-time persisted after all, define it with `defineCollection` + a normal loader.","In shared code, branch on the collection type or accept a fetcher so both collection kinds can use it."],"exampleFix":"// before\nconst products = await getCollection('products');\n\n// after\nconst products = await getLiveCollection('products');","handlingStrategy":"type-guard","validationCode":"// src/lib/collections.ts — keep one source of truth for which collections are live\nimport { getCollection, getLiveCollection } from 'astro:content';\n\nconst LIVE_COLLECTIONS = new Set(['products']); // keep in sync with live.config.ts\n\nexport function isLiveCollection(name: string): boolean {\n  return LIVE_COLLECTIONS.has(name);\n}\n\nexport async function getAnyCollection(name: string) {\n  return isLiveCollection(name) ? getLiveCollection(name) : getCollection(name);\n}","typeGuard":"import type { CollectionKey } from 'astro:content';\n\ntype LiveKeys = 'products'; // derive from your live config\ntype StoredKeys = Exclude<CollectionKey, LiveKeys>;\n\n// overloads make the wrong call a compile error\nexport function get(name: LiveKeys): Promise<ReturnType<typeof getLiveCollection>>;\nexport function get(name: StoredKeys): Promise<ReturnType<typeof getCollection>>;\nexport function get(name: string) {\n  return name === 'products' ? getLiveCollection(name) : getCollection(name);\n}","tryCatchPattern":"try {\n  const items = await getCollection('products');\n} catch (err) {\n  if ((err as any)?.code === 'UnknownContentCollectionError' && /live collection/.test(err.message)) {\n    const items = await getLiveCollection('products'); // fall back to the correct API\n  } else throw err;\n}","preventionTips":["Wrap every collection access in small named helpers so the live/stored split lives in one file.","When adopting live collections, grep the codebase for getCollection(/getEntry( and update each call."],"tags":["content-collections","live-collections","runtime-api"],"backgroundTag":"live-collection-api-misuse","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}