Dataview query against inline field with one vs. multiple values

What I’m trying to do

Most of my notes have tags in the form “Tags:: [[Link1]] [[Link2]]”. For my MOCs, I want to query notes that have a specific tag. Example scenario of what I want to do:

// Note1
Tags:: [[Notes MOC]]
// Note2
Tags:: [[Notes MOC]] [[TEST]]
// Note3
Tags:: [[NOT Notes MOC]]

What I would now like to do in my MOC:

// Notes MOC
```dataview
LIST
FROM "Note1" OR "Note2" OR "Note3"
WHERE contains(Tags, [[Notes MOC]])

However, that will only display Note1. Using:

// Notes MOC
```dataview
LIST
FROM "Note1" OR "Note2" OR "Note3"
WHERE contains(Tags, "Notes MOC")

Will only display Note2.

The underlying issue seems to be that only having one link in the inline field is treated as string while having more will be treated as array?
I can obviously get it to work by treating the single-value (string) case explicitly:

// Notes MOC
```dataview
LIST
FROM "Note1" OR "Note2" OR "Note3"
WHERE contains(Tags, "[[Notes MOC]]") OR Tags = [[Notes MOC]]

But I don’t see this as something I should have to do in every single query in the future. I know that I will forget that way too easily.
Is there another / more obvious way to handle this better / automatically?

Solution:

I’m now using YAML properties for this. They can have a proper type and make queries very easy. I’ve added a “Links” property of type list that now holds what was in the “Tags” inline field before.

To show everything in “Notes MOC.md”:

LIST
FROM "Note1" OR "Note2" OR "Note3"
WHERE contains(Links, [[Notes MOC]])

Properties with a given type is a good way to go. Given inline fields with either a single or multiple values, you could also use flat(list(yourField)) to coerce those values into a list.

However, using Tags as an inline field name is slightly dangerous as you could run into issues related to the predefined tags property.

Anyways, glad you found something which works for you.

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