Finding a node that is not connected in NEO4J Path

Viewed 39

I am new at Neo4J

I have written a query below. I am trying to traverse down the path as show below and to identify any Control nodes that are not attached to a Metric node. I am not particular about the traverse direction, only the connection

MATCH path=(a:Area{Country:"France"})-[b:Scenario]-(c:Threat)-[d:Control]-(e:Control)-[f:Metric]-(g:Metric) WHERE NOT (e)-[f:MetricControl]--(g)
WITH path
MATCH (e) WHERE NOT e IN nodes(path)
RETURN e

However, I keep getting the following errors.

Type mismatch: expected Node but was Relationship (line 2, column 16 (offset: 212))
"WHERE NOT (g)-[f:MetricControl]--(e)"

I was expecting a list of all Control nodes that were part of the Area node that had the property Country :"France" but were not connect to any metric node to be listed.

Any help hints would be greatly appreciated.

1 Answers

I think you mean NOT EXISTS. Here is the syntax:

https://neo4j.com/docs/cypher-manual/current/functions/predicate/#functions-exists

In your example; it should be

WHERE NOT EXISTS((e)-[:MetricControl]-(g))

Notice that you don't need to put the keyword MATCH

Related