Skip to content

Instantly share code, notes, and snippets.

@mneedham
Forked from jexp/create_users.adoc
Last active August 29, 2015 14:01
Show Gist options
  • Save mneedham/ad23156a717f2965430d to your computer and use it in GitHub Desktop.
Save mneedham/ad23156a717f2965430d to your computer and use it in GitHub Desktop.

How to create relatonships between elements in a collection

This GraphGist answers a Stackoverflow question.

Creating A Sample User Graph

We want to create a social network, and have to connect some people. Let’s do that in two steps.

Create a few users

UNWIND ["Amanda","Michael", "Max","Magnus","Mark","Peter","Andres"] AS name
CREATE (:User {name:name})

Connecting users starting with M

MATCH (u:User)
WHERE u.name =~ 'M.*'
WITH collect(u) as users

UNWIND users AS u1
UNWIND users[1..] AS u2

create (u1)-[:knows]-> (u2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment