Neo4j gets edges between nodes of the 1st degree

Suppose I have graph dependencies defined as A-> B, A-> D, C-> A, B-> C, B-> D. I need to get the following subgraph in Neo4j -

  • Get all connections of the 1st degree (independent or outdated) node, i.e. for node A it will be B, C, D
  • Get all the faces between these 1st degree nodes. Since B, C, D are 1st degree compounds, the edges are B-> C, B-> D

For the first part, I have the following query -

MATCH (s:Node)->(d:Node) 
WHERE s.name = 'A' OR d.name = 'A'

I cannot get the second part of the data in the same query. Do I need to sort through all the nodes?

+4
source share
1 answer

, , node, node , node:

MATCH (A:Node {name:'A'}) WITH A
MATCH (A)--(FD1:Node)-[r]-(FD2:Node)--(A) 
  WHERE ID(FD1) > ID(FD2)
RETURN FD1, r, FD2

P.S. , .

+3

Source: https://habr.com/ru/post/1676230/


All Articles