Query Collections in Astro
From the Astro cheat sheet · Content Collections · verified Jul 2026
Query Collections
astro
---
import { getCollection, getEntry } from 'astro:content';
// Get all entries
const allPosts = await getCollection('blog');
// Filter entries
const publishedPosts = await getCollection('blog', ({ data }) => {
return data.draft !== true;
});
// Get single entry
const post = await getEntry('blog', 'my-post-slug');
---✅ getCollection() fetches entire collection as array
💡 Filter function receives {id, data} for each entry
🔍 getEntry() fetches single entry by collection and id
⚡ Access frontmatter via .data, entry id via .id
getCollectiongetEntryquery