How to find and delete the nodes that are not connected to any other nodes?

What I want to do

Hi, I’d like to find and delete the nodes that are not connected to any other nodes.

What I did

I’m using DQL, I tried some queries, but none of them worked :frowning: Also, it’s better if we could run it fast. Thank you very much~~

Dgraph metadata

dgraph version

The version of dgraph I am using is v21.03.2.

I think your best bet is to identify a set to start with and find the ones in that set not connected over an edge with @filter(NOT has(<myedge>)). In a upsert, you can delete predicates from those nodes then.

Note you cannot actually delete nodes, just delete the predicates from them. Because of the storage being arranged by predicate, a node with no predicates takes no storage and is functionally ‘deleted’.

1 Like