Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Created May 3, 2019 16:07
Show Gist options
  • Save vladbatushkov/75c20889704bc9886f8bdda054adf1c3 to your computer and use it in GitHub Desktop.
Save vladbatushkov/75c20889704bc9886f8bdda054adf1c3 to your computer and use it in GitHub Desktop.
Order planets.
MATCH (p)
WHERE p:Star OR p:Planet
WITH min(p.order) as fromN, max(p.order) as toN
UNWIND apoc.coll.pairsMin(range(fromN, toN)) as pair
MATCH (p1 { order: pair[0] })
WHERE p1:Planet OR p1:Star
MATCH (p2:Planet { order: pair[1] })
MERGE (p1)-[:NEXT]->(p2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment