Skip to content

Instantly share code, notes, and snippets.

@latant
Last active October 8, 2020 17:33
Show Gist options
  • Save latant/37930417c5f557427847f6feca7e6816 to your computer and use it in GitHub Desktop.
Save latant/37930417c5f557427847f6feca7e6816 to your computer and use it in GitHub Desktop.
Loading distinct nodes and relationships with patterns in Neo4J 4.0
call {
match p=()--()--() return
reduce(ns = [], n in collect(nodes(p)) | ns + n) as ns,
reduce(rs = [], r in collect(relationships(p)) | rs + r) as rs
}
call { with ns unwind ns as n return collect(distinct n) as nodes }
call { with rs unwind rs as r return collect(distinct r) as relationships }
return {nodes: nodes, relationships: relationships}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment