Looking for help with Dataview Query

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I have a few notes that relate to various people in my life. I use YAML to create that relationship. It looks something like this:

people:
  - "[[Sakshi Chopra]]"
  - "[[John F Frederick]]"

I am trying to list all notes that has Sakshi mentioned in them, but failing.

Things I have tried

Queries I have tried are:

LIST
FROM ""
WHERE contains(people, "Sakshi Chopra")
LIST FROM "/"
WHERE people
  AND any(people, (p) => 
    contains(p, "Sakshi") or 
    contains(p, "[[Sakshi Chopra]]") or 
    contains(p, "Sakshi Chopra")
  )
SORT file.name ASC

No Luck :man_shrugging:t2:

In your example, the people property is of type “array”. The contains() function doesn’t seem to like working with it in this format. The simplest approach would be to convert the people propery to a string. The following worked for me.

```dataview
LIST 
WHERE contains(string(people),"Sakshi Chopra")
```

There might be some other Dataview function you could call that could search the people property without type casting, but this seems like a robust solution for any data you choose to place in other notes.

Like @FsOver2 eludes to proper matching depends on what the contents of your property are like. If you’re sure you’ve got all links in a list property, you could also use contains(people, link("Sakshi Chopra")) to locate that personer.

If your property is not a list, you could use something like people = link("Sakshi Chopra"), and further more if your property doesn’t contain links, you could use either contains(people, "Sakshi Chopra") in the list context, or people = "Sakshi Chopra" if its a single value outside of a list.

So it’s a little confusing when to use what, which is why we sometimes sees the contains(string(people), "Sakshi Chopra") syntax suggested in the other post. This would work for both links and simple text, and in most cases both for lists and single values.

There is one notable case, where it wouldn’t work and that is to match against something [[Sakshi Chopra|My friend]], that is aliased links. Then the string() conversion should pick up the alias, and not the actual link object.

1 Like