Dataview Querying from Metadata, Not Tags

I want a table-style list of notes with a type: “” metadata. For example, I want a list of games from the metadata type = games

TABLE where type = game
sort name asc

Doing so pulls every note in my vault, regardless of whether the type (in every note’s metadata) has “games” in it.

This seems like a very simple request; is it too simple for dataview to understand? I don’t want to use tags for this situation, because I don’t want the tags floating around other defining tags (such as tags for daily activities or specific info related to a story I’m writing).

You’ll want to use a string value.

table where type = "game"
sort name asc

Doing so results in nothing being pulled. Is there a specific way my metadata should formatted? Currently it’s:

type = game

To set metadata, you can either use YAML front matter, where you start the document with a block of YAML contained by three dashes:

type: game

Rest of document

Or, you can use double colons within the document:

# Title at start of document, for example

type:: game

Rest of document

type = game written somewhere in a document won’t establish anything. There may be other ways to set metadata, but those are the two common ways I know.

Forgive me, my formatting was wrong in my response. I am using:

type = game

And nothing is returned when I do:

TABLE where type = "game"
sort name asc

I just found my error!
metadata needs a colon, not an equal sign. But in the query, you use an equal sign. I was interchanging the two at the same time to try and solve it.

Thank you for your help!

Great! Glad you got things working. :grinning:

Just to recapture this:

  • in the frontmatter (or YAML) you’ll use one colon, :, when defining your fields
  • in the main text, you’ll need two colons, ::, to define the fields
  • when checking for equality in an ordinary DQL query (aka ```dataview) you’ll need one equal sign, =
  • and finally, in a dataviewjs query (aka ```dataviewjs), you’ll need two equal signs, ==, to check for equality

Kind of confusing, but there you have it.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.