Astro Content Collections v2 introduces the Content Layer API with explicit loaders, replacing the implicit file convention. Loaders can source data from local files, APIs, or CMSes, making collections a flexible data layer for any Astro project.
0 / 5 completed
1 / 5
What function is used to define a content collection in Astro's Content Collections v2 API?
defineCollection() is exported from astro:content and used inside src/content/config.ts to declare a collection's schema and loader. Each call specifies a Zod schema (via schema) or a loader function and is exported as part of the collections object.
2 / 5
In Astro Content Collections, what does the reference() helper do?
reference() creates a relational field in a collection's schema that points to another collection. For example, author: reference('authors') in a blog schema means each blog post's author field must be a valid slug from the authors collection, and Astro provides the full referenced entry when queried.
3 / 5
What is the glob loader in Astro Content Collections v2?
The glob loader (loader: glob({ pattern: '**/*.md', base: './src/posts' })) is Astro's built-in Content Layer loader that scans a directory for files matching the pattern and auto-populates the collection. It replaces the implicit Markdown convention of v1 with an explicit, flexible API.
4 / 5
How do you restrict a content collection field to a fixed set of values using Zod in Astro?
z.enum() is the Zod validator for fields that must be one of a fixed set of string values, e.g., status: z.enum(['draft', 'published', 'archived']). Astro re-exports Zod from astro:content as z, so no separate Zod import is needed in the config file.
5 / 5
What is the difference between Astro Content Collections v1's implicit file convention and v2's Content Layer API?
Astro's Content Layer API (v2) replaces the implicit file-based convention with explicit loaders. The loader property can be the built-in glob(), a custom async function, or a third-party loader package that fetches from a CMS or API. This makes collections a general-purpose data layer, not just a Markdown reader.