Obsidian Dataview: Querying Your Notes Like a Database
AI-Generated Content
Obsidian Dataview: Querying Your Notes Like a Database
Obsidian excels at letting you create a network of interconnected notes, but what if you could treat that entire network as a searchable, sortable database? This is the transformative power of the Dataview plugin, which elevates Obsidian from a static note-taking tool into a dynamic personal knowledge management system. By adding simple metadata to your notes, you can write queries to automatically generate tables of your top-rated book summaries, lists of pending project tasks, or overview dashboards that update in real-time. Mastering Dataview means your notes start working for you, surfacing connections and information you didn't even know you had.
Understanding Dataview's Foundation: Metadata
Before you can query anything, your notes need data to query. Dataview reads metadata—structured information about your note's content. You provide this data in two primary ways.
The first is YAML frontmatter, a block of key-value pairs at the very top of a note, enclosed by three dashes (---). This is ideal for note-level properties. For a book note, your frontmatter might look like this:
---
title: "Dune"
author: "Frank Herbert"
genre: "Science Fiction"
rating: 9
date-read: 2024-03-15
---The second method is inline fields, which you write directly in your note's content. These are perfect for capturing information within a section, like a task. You write them as a key:: value pair. For example, in a project note, you might have: - [ ] Finalize project proposal due:: 2024-10-30 priority:: high. The key (like due or priority) becomes queryable metadata for that specific line or, in some contexts, for the entire note.
Think of your vault as a spreadsheet: each note is a row, and the metadata fields (author, rating, due) are the columns. Dataview is the powerful formula and filter tool that lets you make sense of all those rows and columns.
Writing Your First Query: The Dataview Query Language (DQL)
The simplest way to query your metadata is using the Dataview Query Language (DQL), a SQL-like syntax designed to be readable and powerful. A basic query has four clauses: LIST, TABLE, or TASK to define the output; FROM to specify which notes to search; WHERE to filter results; and SORT to order them.
Let's create a dynamic table of all your book notes, sorted by rating. You would create a new note (e.g., "Book Dashboard") and insert a Dataview code block:
TABLE title, author, rating, genre FROM #book WHERE rating SORT rating DESC
This query does the following:
-
TABLE title, author, rating, genre: Outputs a clean table with these four columns. -
FROM #book: Looks in all notes tagged with#book. -
WHERE rating: Filters to only include notes that actually have a "rating" field (to avoid errors). -
SORT rating DESC: Orders the results from highest rating to lowest.
The result is an auto-updating leaderboard of your reads. When you add a new book note with a rating field, it will instantly appear in this table in the correct ranked position.
Building Advanced Queries: Filtering, Grouping, and JavaScript
DQL becomes incredibly powerful when you combine its clauses to solve specific problems. A common use case is managing projects. Imagine you have project notes where tasks are written as checklists with inline fields.
To get a list of all incomplete, high-priority tasks across your vault, you could write:
TASK FROM "Projects" WHERE !completed AND priority = "high" SORT due ASC
This TASK query scours the "Projects" folder for any markdown task (- [ ]), filters for those that are not completed (!completed) and are of high priority, and sorts them by their due date, so the most urgent items appear first.
For even more complex data manipulation, Dataview offers a JavaScript API. This is for when you need to perform calculations, manipulate text, or create highly customized outputs. For instance, you could calculate the average rating of all books in a specific genre:
const books = dv.pages('#book').where(b => b.genre == "Science Fiction");
const avgRating = dv.array(books).map(b => b.rating).average();
dv.paragraph(**Average Sci-Fi Rating:** ${avgRating.toFixed(1)});
This script filters pages for the Sci-Fi genre, extracts their ratings into an array, calculates the average, and displays it. While DQL handles 80% of use cases, the JS API unlocks the remaining 20% of powerful, programmatic control.
From Queries to Dashboards: Creating a Central Hub
The ultimate application of Dataview is building a dashboard—a single note that aggregates key information from across your vault. This becomes your command center.
A comprehensive dashboard might contain several query blocks:
- A
TABLEof recently modified notes. - A
TASKlist of overdue items. - A
LISTof meeting notes from the last week, grouped by project. - A
dataviewjswidget showing your current reading stats (e.g., books read this month, top genre).
By placing these in a note you open daily, you create a living, breathing overview of your knowledge base and work. The dashboard proactively surfaces what's relevant, eliminating the need to manually search through folders. It turns your vault from an archive into an active intelligence system.
Common Pitfalls
- Missing or Mismatched Metadata: The most frequent error is a query returning no results because of a typo in a field name or tag. If your query is
FROM #boook, it won't find notes tagged#book. Always double-check your field names (ratingvs.ratings) and ensure they are consistently formatted (e.g., always usingdate-readinstead of sometimes usingdate_read).
- Incorrect Field Value Types: Dataview treats numbers, text, and dates differently. If you write
rating: "9"(in quotes) in your YAML, it's a text string, not a number. You can't sort it numerically or calculate an average. Similarly, always use the ISO formatYYYY-MM-DDfor dates to ensure proper sorting and date arithmetic.
- Overcomplicating with JavaScript Too Early: Beginners often jump to the complex JavaScript API for problems easily solved with DQL. First, master
TABLE,WHERE, andSORTwith DQL. Its syntax is simpler and the queries are easier to read and debug. Only reach fordataviewjswhen you need operations like complex calculations, data transformation, or custom rendering that DQL cannot handle.
- Ignoring Query Performance: While usually fast, a query scanning thousands of notes with complex
WHEREfilters or JavaScript logic can slow down Obsidian. For large vaults, use specificFROMclauses (likeFROM "folder"orFROM #specific-tag) to limit the scope of notes Dataview must process, rather than querying from the entire vault (FROM "") unnecessarily.
Summary
- Dataview transforms Obsidian into a queryable database by reading metadata stored in YAML frontmatter and inline fields (key:: value).
- The Dataview Query Language (DQL) uses intuitive clauses like
TABLE,FROM,WHERE, andSORTto create dynamic lists and tables that auto-update as your notes change. - For ultimate control, the JavaScript API (
dataviewjs) allows for programmatic data manipulation, calculations, and custom output formatting. - The plugin's real power is realized in building dashboards—central notes that aggregate multiple queries to provide a live overview of your projects, reading, tasks, and knowledge.
- Success depends on consistent metadata practices and starting with simpler DQL queries before advancing to more complex JavaScript-based solutions.