Guides guides/query-frontmatter.md

Query YAML frontmatter from the command line

Use the mdbase CLI to filter Markdown files by a YAML property. Return paths, inspect a matching note or get structured JSON for a script.

Run mdbase query --where 'status == "awaiting-count"' in a collection folder. It reads the YAML properties in your Markdown files and prints one matching path per line. You can do this locally without signing in.

1. Prepare two notes with different statuses

Download the mdbase command-line tool for your platform and put the executable on your path. In a new folder, save this configuration as mdbase.yaml. The examples below use a Bash-compatible shell.

mdbase.yaml
spec_version: "0.3.0"
name: Field research

Create a subfolder named surveys. Save this first note there as east-bank.md. The dashes delimit the YAML, and the blank line separates it from the field instruction.

surveys/east-bank.md
---
title: East bank survey
status: awaiting-count
---

Return at low tide to count the nesting pairs.

Save a second note as surveys/west-bank.md with the title West bank survey, status counted and body Counted three nesting pairs at high tide. Open a terminal in the folder containing mdbase.yaml. Run mdbase --version and ls surveys to check your setup.

The terminal shows mdbase 0.1.43, both survey filenames and the collection configuration.The terminal shows mdbase 0.1.43, both survey filenames and the collection configuration.

2. Filter by a property

Run each query from the collection folder
mdbase query --where 'status == "awaiting-count"'
mdbase query --where 'status == "counted"'

The first command prints surveys/east-bank.md. The second prints surveys/west-bank.md. The outer single quotes keep the shell from changing the expression. Inside the expression, double quotes mark a string value. A value that matches neither record produces no paths.

Changing the status filter from awaiting-count to counted returns the other survey path.Changing the status filter from awaiting-count to counted returns the other survey path.
Query two survey notes by status0:05

The CLI prints a different relative path for each status in the sample folder. Silent recording with on-screen captions and sample data.

Text description of the recording
  1. Run a query for awaiting-count.
  2. Read the returned path to the east bank note.
  3. Change the status to counted and run the query.
  4. Read the returned path to the west bank note.

Download MP4

3. Read a result or pass it to a script

Run mdbase read surveys/east-bank.md to print the complete file. Querying a property looks at frontmatter. A word in the body, such as “tide,” does not become a value of status.

The read command prints the east bank record with its two YAML fields and its field instruction.The read command prints the east bank record with its two YAML fields and its field instruction.

For machine-readable output, add --json. The result has a records array. Each entry includes its relative path and a frontmatter object. Add --include-body when you also need the prose.

Return the matching record as JSON
mdbase query --where 'status == "counted"' --json --include-body

From another working directory, put --root "/path/to/Field research" after query. To use the same fields in an application or AI client, see SDK queries and querying records through MCP.