These guides are primarily for agent readers. They explain how agents use Sails. If you are a person, start at sails.app or Add Sails.

Collections

A collection is a named list declared in a page's front matter. glob: lists other pages on the same site. filter: lists JSON and front-matter files. The compiler fills the list when the page is requested and refills it when a matching file changes. It is not Postgres, not a JSON store, and not something you INSERT into.

For app records (contacts, tasks, subscribers), use sql --db. See Keep app data in a database.

Source of truth: /skills/collections.md, /skills/filter.md, and filter --help.

Done looks like

An index page lists every matching page or file. A new post file appears in that list after autosave, with no rebuild command and no second ship create.

Worked example 1: a paginated blog index (glob:)

This site already uses glob:. pages/index.page.html and pages/how-to/index.page.html both declare one.

From a fresh site:

cp -r /templates/static-blog ./site

site/pages/index.page.html already has posts: with glob: pages/blog/**. Add site/pages/blog/launch.page.md:

---
title: Launch
date: 2026-08-19
draft: false
---
<site-shell title="{{ title }}">
# Launch

Shipped.
</site-shell>

To page the list, add paginate: and read _pagination.<key>:

---
title: Paged
posts:
  glob: pages/blog/**
  where: draft != true
  sort: date
  order: desc
  paginate: 2
---
{% for post in posts %}
  <a href="/{{ post._url }}">{{ post.title }}</a>
{% endfor %}
{% if _pagination.posts %}
  page {{ _pagination.posts.page }} of {{ _pagination.posts.pages }}
  ({{ _pagination.posts.total }} posts, {{ _pagination.posts.limit }} per page)
{% endif %}

Ship once: ship create site --path site --policy 644. --path is from the repository root, not your current folder.

What a live test page at /paged returned, with 7 published posts and 1 draft:

URLItems_pagination.posts
/pagedPost 5, Post 4page 1, pages 4, total 7, limit 2
/paged?page=3Post 1, Markdown Postpage 3, pages 4, total 7, limit 2
/paged?limit=10all 7page 1, pages 1, total 7, limit 10
/paged?page=9the last pagepage 4 (clamped), pages 4

The draft is not in total, because where: draft != true drops it before paging. A page number past the end returns the last page, not an empty list.

Each glob: item is the other page's front matter plus _url (public path, no leading slash, like blog/launch) and _source (the file path from the repository root, like site/pages/blog/launch.page.md).

On this guides mount the public prefix is /guides, so links here are /guides/ plus _url. A site published at folder root uses / plus _url, as /templates/static-blog does.

Worked example 2: a list of JSON records (filter:)

Put one JSON object per file under the site root:

mkdir -p site/data/invoices
echo '{"title":"Acme","status":"open","amount":120}' > site/data/invoices/acme.json
echo '{"title":"Bolt","status":"paid","amount":80}' > site/data/invoices/bolt.json
echo '{"title":"Cove","status":"open","amount":300}' > site/data/invoices/cove.json
---
title: Invoices
invoices:
  filter: data/invoices/**
  where: status = open or (status = paid and amount > 50)
  sort: amount
  order: desc
---
{% for row in invoices %}
  <p>{{ row.title }}: {{ row.amount }} ({{ row._path }})</p>
{% endfor %}

Live output: Cove 300, Acme 120, Bolt 80. Each item is the stored object plus _path. There is no _url, because a JSON file is not a page.

Run the same query from a shell or handler to see what the page will get:

filter 'site/data/invoices/**' --where 'status = open' --order amount:desc --paths
filter 'site/data/invoices/**' --agg count --agg sum:amount
# {"amount":500,"count":3}

JSON numbers sort as numbers, so sort: amount / order: desc gives 300, 120, 80. Numeric-looking strings stay text ("120" is not coerced to a number). ISO dates still sort correctly as text. Null or missing values sort last. In a mixed field, numbers stay before strings in both directions; desc only reverses order within a type.

Front-matter keys

Declare the list under any name (posts, howtos, invoices). Each collection sets glob: or filter:, not both.

KeyWhat it does
globPage files relative to the site root (the folder with sails.site.json). Example: pages/blog/**
filterJSON and front-matter files (same set as the filter command), relative to the site root. Example: data/invoices/**
whereSQL-like field op value, joined with and / or and parentheses. Missing fields are null
sortField name (date, nav_order, title, amount). JSON numbers sort as numbers; strings, including ISO dates, stay text. Null or missing last
orderasc or desc
paginatePage size. ?page= and ?limit= override it per request. The collection variable holds the current page; totals are on _pagination.<key> (page, limit, total, pages)
searchtrue enables ?search= / ?q= semantic search within the set

where examples:

where: draft != true
where: draft != true and date != null
where: status = open or (status = paid and amount > 50)
where: id = $threadId

$threadId is a splat from a file like pages/threads/$threadId.page.html. The captured value is also a template variable named threadId.

What is not a collection

Tempting file / keyReality
sails.data.jsonDo not use. Not how app records work
Page from: or page sql:Do not use for records
collection query contactsNot a command. Use filter for JSON files or sql --db for rows
Writing a row from a formHandler talks to sql --db, not to a glob

Copy /templates/crm-app (or remix-app / table-app) when the job is rows. For a full showcase of collections, import maps, and remix/component, copy /templates/static-site-demo.

Failure modes

What you seeWhat it meansWhat to do
check error: collection cannot set both `glob:` and `filter:`; use `glob:` for pages or `filter:` for JSON / front-matter filesOne collection has both keysSplit it into two collections
Loop is emptyGlob or filter path missed, or where dropped every itemPath is from the site root (pages/blog/**, data/invoices/**). draft: true pages are dropped by draft != true. A page with no draft key is null, so draft != true keeps it
Items show but title is blankThat file's front matter did not parseThe file must start with a --- line, then YAML, then ---. A file written with a broken printf often starts with --
A draft appears in the listIts front matter did not parse, so draft is nullSame fix as above
A numeric-looking string sorts with strings, not with numbersThe field is a string, so it stays textStore a JSON number when you want numeric order
New post or edited JSON missing on the live URLAutosave has not landed yetWait a second and reload. The page recompiles when collection files change. Do not ship create again
You used filter: and expected _urlfilter: items are files, not pagesRead _path. For page URLs use glob:
check warning: relative --path resolved from the current directorycheck paths are relative to your folder; ship create --path is from the repository rootUse the root-relative path for ship
You put contacts in sails.data.jsonWrong store.db bundle + sql --db. See Keep app data in a database
check --path template errorThe template failed the same way publish wouldFix the loop syntax and quotes. Do not HTML-escape quotes inside if expressions

How to: Publish a site, Filter JSON files, Keep app data in a database. Also Static sites, Filter, SQL.