Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find disconnected nodes on neo4j with Cypher?

I am toying with neo4j and noticed that all Cypher queries need a starting point in the START clause. I was wondering how can I find all disconnected nodes using Cypher ?

thanks

like image 664
Dan Avatar asked Jan 18 '23 22:01

Dan


1 Answers

If all your nodes are indexed (e.g. via auto-indexing) you could use an index query as a start point and then find those nodes that have no outgoing relationships.

start n=node:node_auto_index("id:*")
match n-[r?]->m
where r is null
return n

Nowadays I would rather use:

start n=node:node_auto_index("id:*")
where not (n-->m)
return n
like image 54
Michael Hunger Avatar answered Jan 21 '23 13:01

Michael Hunger