Create relationships according to the order of the nodes property values


I have a graph database. The nodes in the graph suppose to be connected based on the order of the given property values. For example, the graph nodes can be:

(a{p:1}) (b{p:3}) (c{p:6}) (d{p:8})

then the connections suppose to be:


according to the order of the p value.

Where the problem is that the p values are randomly given.

So, how can I create the relationships between the nodes by Cypher?

Could you guys give me any suggestions? Thanks a lot!

MATCH (n:NodeLabel)
WITH n ORDER BY n.propertyValue
WITH COLLECT(n) as nodeList
RETURN nodeList

1 Like

Hi @ganesanmithun323, thanks for your answer. While could you give more explanations for the operation. Neo4j is a pretty new platform for me. Thanks a lot!

HI @hn.chen , apoc is a kind of plugin which you can install in your db has lof of useful functions ..

know more about apoc here :

1 Like