Dataview: Query by document property

What I’m trying to do

I’m trying to query files that possess particular properties. The properties themselves don’t need to have any specific value, or even a value at all (the property could be empty for all I care). I’m more concerned with whether or not those files have said property.

Things I have tried

I’ve been using this:

TABLE
WHERE file.frontmatter.related
SORT file.name ASC

…And it sort of works. It will report any files with the “related” property, so long as they have a value of some kind set, like this:

---
related: "[[some other file]]"
topics:
  - "[[grocery list]]"
tags:
  - organizer
  - status/ongoing
---

But it will not find files like this:

---
related: 
topics:
  - "[[grocery list]]"
tags:
  - organizer
  - status/ongoing
---

I’ve looked around and seen some suggestions for using “contains”, but again, I think that will only work when the property has a specific value. Unless there’s a way to use that to query files that contain said property?..

Aside from that, the questions I’ve come across are usually looking for a property with a particular value.

If an explanation is needed: I realize this is probably a really bad way to find the files I want - querying by a property name, instead of the property value.

I made the mistake of adding a really pointless, redundant property to my YAML header in a bunch of my files. So, instead of going through each file, one by one from the file tree, I’m trying to see if there’s a way I can just pull all the files that still have the property.

Thanks in advance.

I think I’ve got it:

TABLE 
WHERE contains(file.frontmatter, "related")
SORT file.name ASC

I used “contains” to check the file’s frontmatter property for the presence of “related”.

Don’t ask me how it works, but apparently it does.

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