0
votes

Background:

I have a graph with Company nodes joined to eachother through One or MORE relationships.

Looks like this:

enter image description here

Trying to Achieve:

I want to keep all nodes where the relationship between them is "competes_on_backlinks" BUT if another relationship of "links_to" exists between them THEN filter out that node.

I have Tried:

MATCH p =(c:Company {name:"example.com"})-[r]-(b:Company) where NONE (x IN relationships(p) WHERE type(x) ="links_to") RETURN p

The above query produces the graph in the image.

That filters out nodes where the ONLY relationship between them is "links_to" BUT it does not remove the nodes where there is another relationship as well(as you can see in the image)

So many other attempts but the same result.

Any idea how to do this?

1

1 Answers

1
votes

The NOT operator can be used to exclude a pattern:

MATCH p = (c:Company {name:"F"})-[:competes_on_backlinks]-(b:Company) 
WHERE NOT (b)-[:links_to]-(c)
RETURN p