Reputation: 11
create a relationship between nodes with the property input
and output
where the output value of a node becomes input value to another node.
for example i have 4 nodes, each node has property:
this is my cypher code :
MATCH (n:node), (m:node)
WITH n.output as output, m.input as input
FOREACH (output in n |
FOREACH (input in m |
MATCH n, m
WHERE output = input
MERGE (n)-[:NEXT_TO]->(m)
)
)
the output of the cypher code above should be the relation NEXT_TO
from node 1
to nodes 2
and 3
, relation NEXT_TO
from node 2
to node 4
and relation NEXT_TO
from node 3
to node 4
.
Upvotes: 1
Views: 50
Reputation: 30397
Perhaps something like this?
MATCH (n:node)
UNWIND n.output as output
MATCH (m:node) WHERE output IN m.input
MERGE (n)-[:NEXT_TO]->(m)
Upvotes: 1