#Should I use `type: data` in astr collections?
4 messages · Page 1 of 1 (latest)
Hi @old jewel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
No, you should not use type: 'data' in modern Astro content collections.
The type field (both type: 'content' and type: 'data') was part of the legacy v2.0 Content Collections API. As of Astro v6, this field is no longer valid and must be removed from your collection definitions. If you include it, you'll get a ContentCollectionInvalidTypeError. [invalid type error]
Instead, all collections now use the Content Layer API, which requires a loader instead of a type. For example:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import { glob, file } from 'astro/loaders';
const blog = defineCollection({
// No `type` field — use a loader instead
loader: glob({ pattern: '**/*.md', base: './src/data/blog' }),
schema: z.object({
title: z.string(),
description: z.string(),
pubDate: z.coerce.date(),
}),
});
const dogs = defineCollection({
loader: file('src/data/dogs.json'),
schema: z.object({
id: z.string(),
breed: z.string(),
temperament: z.array(z.string()),
}),
});
export const collections = { blog, dogs };
If you're unable to migrate immediately, you can temporarily enable the legacy.collectionsBackwardsCompat flag in your Astro config, but this is only a short-term workaround: [legacy flags]
// astro.config.mjs
export default defineConfig({
legacy: {
collectionsBackwardsCompat: true,
},
});