Bases: Access (the number of) incoming links (backlinks) of a file

Use case or problem

While I have already successfully replaced most my dataview-queries with Bases (I personally prefer native functions aka core plugins over community ones), I noticed that I currently cannot access the number of incoming/outgoing links of a file.

This was quite a cool function in dataview where I could sort files by the number of links the file contained via this syntax:

length(file.inlinks) as "in", length(file.outlinks) as "out"

Another cool function in dataview was this code to display all files that link to a note but are not linked backwards:
contains(this.file.inlinks, file.link) AND !contains(this.file.outlinks, file.link)

Proposed solution

I would love to have more information about the file such as the number of in-/outlinks available to us in Bases so that we can create even cooler Tables/Overviews!

4 Likes

Okay, so I managed to find a filter to get all the files that link to the current-file (the base is embedded in), but that are not linked back from the current file:

filters:
  and:
    - linksTo(file.file, this.file.path)
    - not:
        - linksTo(this.file.file, file.file)

Thats already great, but I would still love to find out how many files link to/from the current file :slight_smile:

2 Likes

This code no longer works with Obsidian v1.9.2 - the new working filter is:

filters:
  and:
    - file.hasLink(this.file)
    - not:
        - this.file.hasLink(file.file)

With the new functions/syntax in v1.9.2 it is now also possible to get the number of outgoing links from the current file with this formula:

file.links.length

So now the only thing still missing from my feature request is the ability to access the number of incoming links to the current file.

3 Likes

renamed for clarity

2 Likes

sorry if this is a dumb question - where do I paste this code to make it work in my Base?

All good, don’t worry! There are two ways you can create a base - one is through the “UI” and the other is as a “Code-Block” (similar to how we used Dataview all the time).

The “Code” I provided is copied from a base-codeblock:
ezgif-4533d1057dc8a5

You can also simply paste the lines separately into the filter-UI of a Base by using the advanced formula editor:
ezgif-465b910551270e
Just make sure you select the All are true/None are true-Options to relate the filters:
ezgif-45351a0c747719

Regarding file.links.length - this is just a property-formula:
ezgif-47c7d99fc83571

I hope this helps :blush:

1 Like

+1

displaying the number of incoming links is one of the last things I can do with dataview but can’t do with bases…

1 Like

Yes exactly - I have personally already replaced all my Dataview-Queries with Bases and this is the only thing missing for me - sadly I really like to see both the number of incoming and outgoing links to get an overview “how well connected” a note is already :slight_smile:

Hopefully the Obsidian-Team can figure out a good (performant) way to implement this - other than that I really enjoy Bases and love the direction Obsidian is going with them!

2 Likes