2
votes

Let's say I have generated an unknown amount of nodes with the same label. Then I would like each node to be in relationship with all the others...

I tried the following CYPHER :

MATCH (n:Nodelabel),(m:Nodelabel)
MERGE (n)-[:EXCHANGE {cost: rand()*100}]->(m)

It's almost perfect but I get looping relationships : each node is in relationship with himself. How can I prevent that?

1

1 Answers

3
votes

Use the following CYPHER :

WHERE NOT n=m

So the full CYPHER answer is :

MATCH (n:Nodelabel),(m:Nodelabel)
WHERE NOT n=m
MERGE (n)-[:EXCHANGE {cost: rand()*100}]->(m)