FAQ Guide for Obsidian Dataview

-

Who this guide is for?

Any person looking to get started but feels that the documentation is too intimidating. SkepticMystic’s guide is actually a better guide to help you get started writing queries. This should be viewed as a supplement to it. That said, if you’re a programmer or database expert who’s looking to get started quickly, this guide probably isn’t it. Check out the docs instead.

What is dataview?

It’s a plugin by blacksmithgu. It lets you query data from your Obsidian vault.

What’s a query?

Think of a query as a question you want to ask your Obsidian vault. For example,

  • What notes did I modify in the last 5 days?
  • Which movies are tagged #towatch?
  • What tasks have I tagged #critical?
  • List my favorite books in descending order of rating.

These are just a few examples of what is possible with dataview. Note that you can’t change your metadata with dataview. Look into Christian’s MetaEdit for that instead.

Great, how do I get started?

It’s actually pretty easy to get started. Just install the plugin from the “Community Plugins” list after turning off safe mode.

But wait, how do I query?

Use a dataview code block like so:

```dataview
list
from "Folder"
```

The syntax is rather extensive so refer to the docs copiously. I still do so even after having used dataview for 6 months at the time of writing.

What can I query?

Dataview indexesJust a fancy way of saying “collects”.

“metadata” from your notes. Metadata is meta information about your notes and files. Some of the common metadata fields you might be familiar with are things like “last modified date”, “file creation date”, “file extension”, etc.

There are two types of metadata, for the purposes of dataview. The one we looked at above was “implicit metadata”, which exists for every file in your vault. The list of fields can be found in the docs. Note some of the more useful ones:

  • file.name
  • file.path
  • file.mtime

There’s a second type of (arguably) more useful metadata — the one we define. This lets you create your own indexes to query. Lets look at some examples.

Book.md

---
title: "Iliad"
author: "Homer"
---

Movie.md

---
title: "Citizen Kane"
year: 1941
director: "Orson Welles"
---

Note that for Book.md and Movie.md, the metadata defined there is actually YAML frontmatter. The Obsidian Help docs have a useful section on what that is. Dataview supports YAML but also has support for a custom variant called “inline YAML”, specific only to Dataview.

Inline YAML is a non-standard YAML-like way of specifying additional metadata. This is what is depicted in the example below. It follows the key:: value style. Note that it currently doesn’t support nested fields the same way standard YAML does.

Example.md

This is a sample note. Today I met person:: Adam.

Now that we have some files and metadata defined, let’s talk about indexes, which is what you’re querying against. It’s helpful to think of an index as one big ’ol table that you’re trying to narrow down to precisely what you need. So, in this case, say we had these three metadata examples in our vault, our index would look like this:

title author year director person file.name file.ctime other fields…
“Iliad” “Homer” null null null “Book” 10:19 PM, March 22, 2022 all other
“Citizen Kane” null “1941” “Orson Welles” null “Movie” 10:19 PM, March 22, 2022 explicit and
null null null null Adam “Example” 10:19 PM, March 22, 2022 implicit fields

Querying our three files for title like:

```dataview
table
    title
from
""
```

would give us:

title File
Iliad [[Book]]
Citizen Kane [[Movie]]
null [[Example]]

We queried the title from our index but Dataview also gives us the File column by default.

The rows in your index will depend on what source you’re using. If you’re using "" as a source, the rows will be all the files in the vault. If you’re using #tag as a source, the rows will be all the files with that tag in them. The columns in your index will depend on the metadata that you’ve defined in your files. Task indexes (- [ ] elements that you use for TODOs) are different and they’ll be covered in a separate guide.

To narrow this table down, we typically use filters or WHERE conditions. For layering complication logic, we use functions. For more on what you can do with this index, check SkepticMystic’s guide linked earlier.

What are some gotchas about YAML?

A very important caveat is that this is all you can query. You cannot query the contents of your files. File content is not part of metadata. Remember, metadata is either explicity or implicitly defined as we discussed earlier.

Another gotcha is that wikilinks in Obsidian Frontmatter are not clickable, nor do they show up on your graph. This is a current Obsidian limitation.

Finally, metadata for each file is independent of the other. To rephrase, it means that each file has its own metadata.

How should I define my YAML?

This is a difficult question. You can add nearly any kind of metadata you want to your notes. The open ended nature of this makes it difficult to design “schemas”.Schemas are the database equivalent term for your “metadata structure”.

One solid piece of advice when it comes to “designing metadata” is to think of your end goal first. It’s counterintuitive, I know, but it’ll give you a good idea of what fields you need to use. You can look at the forums for inspiration:

How to debug your queries?

It’s a little difficult to write a correct query on your first try. I still find it tricky even after having used Dataview for more than 8 months at the time of writing. A general rule of thumb is to start with the simpler version of a query and then slowly progress to the actual query that you want.

Another helpful tip is to actually inspect the metadata that’s being queried. You can do this by enabling inline DVJS in the plugin settings and then typing `dv.list([dv.current()])` to inspect that note’s metadata. Remember to use that in a page that actually has the metadata since you’re likely writing the query in a separate file. You’ll note that everything you can query about that page shows up in a bulleted list.

Finally, for debugging more complex queries, these often error out because of some assumptions you’ve made about the data you’re querying or the functions you’re using. Common ones include syntax errors and type mismatches. Test those assumptions by checking the docs.

Let’s also do a quick rundown of some of the common errors/issues.

Some rows are missing

You expected some rows in the output table/list but they’re not there. This usually happens when your FROM or WHERE is incorrect. If your where looks correct, your condition is incorrect. This typically happens when your types are mismatched, such as:

  • Trying to compare a date to a string
  • Trying to compare a string against an array

WHERE or function doesn’t work

“I’m writing what I think makes sense but it doesn’t work.” Often, this happens because the way you think dataview works isn’t the way it actually works, i.e. you’ve made incorrect assumptions. This happens fairly often when doing programming related stuff so fret not. The easiest way is to test this separately and thoroughly consult the documentation.

My output doesn’t look correct

For example, you expected “2022-10-10” but Dataview shows you 10 October, 2022. Dataview converts date strings into date objects. These are displayed using the DD MMMM, YYYY format. It’s actually tricky to work around this. I’ll cover types at some point in the future.

I can’t understand the error messages

That’s fine. Look for some of the obvious syntactical mistakes like:

  • Missing commas
  • Function applied but column name not assigned
  • Invalid commands being used
  • Function arguments incorrect

I did a GROUP BY but my results are gone now

Groups behave a little differently in Dataview. See SkepticMystic’s guide for a quick introduction.

All my output is empty/only has -s

This occurs when the field you’re querying either has no data or doesn’t exist in the index. Inspect the page you’re querying to see what’s happening using the inline DVJS query I mentioned earlier.

[[this page]] doesn’t work

Dataview handles wikilinks a little differently. If you try to do FROM [[certain file]] in a query, it’s actually looking up all files that link to [[certain file]] and not certain file itself. Dataview calls this “inlinks”. Files linked to by the current file are called “outlinks”. See the links section in Sources.

Vault Images don’t work

This is currently a known limitation. There is a workaround involving the file:// URL. However, you can use web images with no issues.

Why do my results appear with bullets?

You might see this happen when your results are an array or are wrapped in an object. You’d have to extract it with a field name or array index.

Something Else

Search through the Discussions and Issues on GitHub. A lot of ground has been covered since Dataview’s initial release and chances are someone has run into your error before. If you still can’t find anything, feel free to open an issue on GitHub and assign it to me. Don’t be shy to drop by on the Discord server either! Mention me in the #dataview thread or in #plugin-advanced and I’ll be more than happy to help you out.

Feedback

If you feel there are some other FAQs you want covered in this guide, feel free to reach out to me on Discord or via email.