03. Sovereign Edge CMS/Collections

Querying Collections & Items

Collections represent dynamic, repeatable content streams like Blog Posts, Team Rosters, Products, and Portfolio Projects with built-in pagination, multi-field filtering, and full-text search.

N+1 PROBLEM SOLVED
20ms
Automated Request Batcher Window

getItem() calls fired across multiple nested components are coalesced into a single network payload automatically.

RequestBatcher Engine
GET/content/:projectId/collection/:collectionId

The getCollection() Method

Queries collection records with server-side pagination, structured filters, and sorting:

1import { nexus } from "@nexushub/client";
2import type { BlogPost } from "@/types/nexus";
3import { generateDocMetadata } from "@/lib/docs-metadata";
4 
5// Auto-generated SEO Metadata
6export const metadata = generateDocMetadata("/docs/content/fetching-collections");
7 
8export default async function BlogArchive({ searchParams }: { searchParams: { page?: string, q?: string } }) {
9 const pageNumber = Number(searchParams.page) || 1;
10 
11 // Query collection with filters, search, and sorting
12 const result = await nexus.content.getCollection<BlogPost>("blog_posts", {
13 page: pageNumber,
14 limit: 12,
15 sort: "published_at",
16 order: "desc",
17 search: searchParams.q,
18 filter: {
19 category: "Engineering",
20 is_featured: true,
21 },
22 });
23 
24 return (
25 <div>
26 <p>Showing {result.items.length} of {result.total} posts</p>
27 <div className="grid grid-cols-3 gap-6">
28 {result.items.map((post) => (
29 <article key={post.id}>
30 <h2>{post.title}</h2>
31 <p>{post.excerpt}</p>
32 </article>
33 ))}
34 </div>
35 </div>
36 );
37}

Query Parameters & Filtering

ParameterTypeRequirementDescription
pagenumberOptionalThe 1-based page index to retrieve.
Default: 1
limitnumberOptionalNumber of records to return per page (min: 1, max: 100).
Default: 10
sortstringOptionalThe field identifier to sort records by.
Default: 'createdAt'
order'asc' | 'desc'OptionalSort order direction.
Default: 'desc'
searchstringOptionalFull-text search query across all string and rich-text fields.
filterRecord<string, any>OptionalExact or array-inclusive matching criteria (e.g., { status: 'published', tag: ['tech', 'news'] }).
includestring[]OptionalArray of relational Reference field keys to expand and hydrate in-place.

Request Batching with getItem()

When building modular interfaces (like an e-commerce cart or author avatar list), multiple components may call getItem() simultaneously. The SDK includes a built-in RequestBatcher that merges all calls made within a 20ms microtask window into a single HTTP round-trip:

1import { nexus } from "@nexushub/client";
2 
3// Multiple instances of this component on the same page will NOT trigger N requests
4export async function AuthorAvatar({ authorId }: { authorId: string }) {
5 const author = await nexus.content.getItem("authors", authorId, {
6 revalidate: 3600,
7 });
8 
9 return (
10 <div className="flex items-center gap-2">
11 <img src={author.avatar?.url} className="h-8 w-8 rounded-full" />
12 <span>{author.name}</span>
13 </div>
14 );
15}

Query across multiple collections simultaneously with a single query:

1import { nexus } from "@nexushub/client";
2 
3const { results, total } = await nexus.content.search("artificial intelligence", {
4 collections: ["blog_posts", "documentation", "products"],
5 limit: 20,
6});