Resurface your Obsidian notes with these Dataview queries

Faiz Khuzaimah / efemkay
5 min readJul 27, 2024

--

Since I have used Obsidian over many years on almost daily basis, my vault has grown to thousands of notes. A good chunk of those were my old notes imported from Notion and OneNote but the bigger chunk are the “insights” I captured since then. For any new note I capture in Obsidian, I would try my best to properly organise (using tags and/or links). But occasionally, whenever I’m in focus mode working or pressed for time, I would do quick capture without proper tags nor linking. Given enough time, there bound to be notes that I have not seen (let alone digest or update) or properly organise in a while.

There are two parts of a similar problem here. One is that I have my fleeting notes that I need to come back to and do something with it. Another is that I have another group of notes that I wanted to revisit especially if I have not done so in a while. This is where I find Dataview plugin [1] to be the solution to my problems. So here how I do it.

Why should you revisit your notes?

But, before I go a bit technical with Dataview, I want to touch briefly on why you should revisit your notes, and equally important, why you should not overdo the process. In my setup, I do not revisit all of my notes but only on a subset of it — specifically the fleeting notes and the permanent notes. I use Obsidian to capture all kind notes, and that include my journal, references like boilerplate CSS codes and logs like history of my car services. For those notes I do not really need to actively resurface them, it is there in case I need to refer to them when I need it.

If you are familiar with Tiago Forte’s CODE method for creating Second Brain [2] (if you are not, links on it is at the bottom), the Capture step outlines 3 principles i.e. (a) capture only the most important information, (b) think like a curator, and (c) keep only what resonates. So, in my (somewhat) weekly review, I include a specific Dataview query to reminds me to review my fleeting notes in the spirit of “keeping only what resonates”.

Another reason why you should revisit your notes is more applicable to permanent (or evergreen) notes and this relates to Bayesian Thinking [3]. It is a thinking practice that not only considers prior knowledge but also to actively take into account new information and adjusts, alter or improve your beliefs. In my case, adjusting or improving the insights my permanent notes give me. You do not want to have amass collection of insights only to discover (when you really need it) that they have been outdated, or worse untrue or no longer valid. Revisit to allow you to adjust your beliefs as more information becomes available.

Here are the run through of my Dataview queries

There a number of Dataview queries I use in my Obsidian vault. But for today, I will be sharing just two — one is to resurface my old fleeting notes for me to act on it, and another to randomly resurface my permanent notes for me to review and possibly update them.

For my fleeting notes, I use a simple Dataview Query Language (DQL) to resurface the relevant notes. From there I would decide if I want to keep it or not. And if I do, I would tag it with the appropriate metadata.

```dataview
LIST dateformat(file.mday, "yyyy-MM-dd")
FROM -("journals" OR "Templates" OR "Areas/Administrative" OR "Archive")
WHERE length(file.inlinks) =0 and length(file.outlinks) =0 and length(file.tags) =0
SORT file.mday ASC
LIMIT 5
```

This DQL structure is simple enough to understand if you are somewhat familiar with it. But just in case, I will go through on the parameters I use.

  • I use DQL’s LIST since that is what I prefer (the other option would be TABLE). You do not have to add anymore after LIST as it would already include the file links, but I added dateformat(file.mday, "yyyy-MM-dd") because I wanted to know how long ago this particular note was last updated. The field is file.mday and the dateformat() function is so that it shows in my preferred ISO 8601 format.
  • I use FROM to filter out the unnecessary folders (before further filtering with WHERE below). Since it is an exclusion it has to be in -(...) format. Here you can see that I do not resurface notes from my journals, templates and other non-knowledge related folders.
  • WHERE is the most important part of this query. I define my most grieving fleeting notes as those super orphan notes. These are the notes that match all these 3 criteria i.e. (i) files without any other file linking to it (length(file.inlinks) =0), (ii) files without any link to any other file (length(file.outlinks) =0) and (iii) files without any tag (length(file.tags) =0).
  • I sorted it so that it shows me the oldest five (5) notes. Why five? Because that is already plenty for me to relook in a single sitting.

For my permanent notes, I have to resort to using Dataview JS Query language (DVJS). I have little to no experience coding in Javascript, but for this case, I had to as DQL (as far as I know) do not have function like Math.random. By the way, I could not even come up with this query; I copied it from Chris Grieser from his Obsidian Vault tour on Danny Hatcher YouTube channel (link below [4])

```dataviewjs
const numberToShow = 5
const notes = dv.pages('#PermanentNote')
.sort(() => 0.5 - Math.random())
.slice(0, numberToShow)
.map(note => note.file.link);
dv.list(notes)
```

I’m not proficient enough to explain the code line by line, so I’m just going to summarise the changes I made compared to Chris’s

  • I use tags #PermanentNote in my notes, so I have it changed to dv.pages(#PermanentNote). So any notes with that tag anywhere in the note would be pulled.
  • Similar to my fleeting notes query, I limit it to just 5 for practicality (coz, you know…)

And… how it looks like as a whole

Dataview is powerful plugin to programmatically query and recollect your notes. If you need to tweak any of the above queries, it may be helpful to go through some of the examples in the official documentation. But I do find s-blu’s compilation of Dataview query example [5] to be most helpful for more real world use cases.

Anyway, this is how my weekly review note looks like with the two Dataview queries above. Well, I did hide half of the original note content for this screenshot because my weekly also consists of my yearly goals summary and my weekly journal summary. In case you are intrigued with the columns look, it is my own CSS snippets shared at my GitHub repo efemkay/obsidian-modular-css-layout: CSS Layout hack for Obsidian.md (github.com). I will be doing a post on that snippet soon.

Hope you find this useful ;)

References

  1. Dataview (blacksmithgu.github.io)
  2. Building a Second Brain: The Definitive Introductory Guide (fortelabs.com)
  3. Bayesian Thinking in Everyday Life | by Chong Han Khai | Medium
  4. Obsidian Vault Tour: Chris (Pseudometa)
  5. Dataview Example Vault (s-blu.github.io)

--

--