Take the 2-minute tour ×

Is there a way to find all nodes of specified type that aren't connected?

Lets say I have nodes with Labels like :UserOrder and :OrderPayment. Paid orders are typically connected like: (user:UserOrder)-[r:PROCESSED {date:xxxxx}]->(order:OrderPayment)

In hypothetical scenario in some cases due to some errors payments aren't processes and as a result are not connected with orders. How would I find all UsersOrders and OrderPayments that aren't connected?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Not sure if this is the fastest way:

WHERE (n:UsersOrder OR n:OrderPayment) AND NOT (n)--()
share|improve this answer
It's convenient to do both in one query, but that means you're not getting the nodes by their labels, but have to first bind all nodes and then test for label, which can be expensive. –  jjaderberg Nov 27 '13 at 13:27
@jjaderberg agreed, making it two separate queries is probably a lot faster –  robertklep Nov 27 '13 at 14:20
add comment

You can filter on the absence of a relationship in the WHERE clause. If you want to exclude the UserOrder nodes that have any relation whatsoever you can do

MATCH (user:UserOrder)
WHERE NOT (user)--()
share|improve this answer
add comment

Your Answer


