Skip to content

Instantly share code, notes, and snippets.

@mneedham
Forked from jexp/create_users.adoc
Last active August 29, 2015 14:01

Revisions

  1. mneedham revised this gist May 22, 2014. 1 changed file with 6 additions and 8 deletions.
    14 changes: 6 additions & 8 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -23,14 +23,12 @@ CREATE (:User {name:name})

    [source,cypher]
    ----
    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)
    MATCH (u:User) WHERE u.name =~ 'M.*'
    WITH collect(u) as users
    WITH users[..-1] AS c1, users[1..] as c2
    UNWIND reduce(acc=[], x in range(0,length(c1) -1) | acc+ [ [c1[x], c2[x]] ]) AS pair
    WITH pair[0] AS p1, pair[1] AS p2
    CREATE (p1)-[:OWNS]->(p2)
    ----

    //graph
  2. mneedham revised this gist May 21, 2014. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -24,12 +24,13 @@ CREATE (:User {name:name})
    [source,cypher]
    ----
    MATCH (u:User)
    WHERE u.name =~ 'M.*'
    WITH collect(u) as users
    foreach ( i in range(1,length(users)-1) |
    foreach (u1 in [users[i-1]] | foreach ( u2 in [users[i]] |
    create (u1)-[:knows]-> (u2) ))
    )
    WHERE u.name =~ 'M.*'
    WITH collect(u) as users
    UNWIND users AS u1
    UNWIND users[1..] AS u2
    create (u1)-[:knows]-> (u2)
    ----

    //graph
  3. mneedham revised this gist May 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    == How to create relatonships between elements in a collection
    :neo4j-version: 2.1.0-RC1
    :neo4j-version: 2.1.0
    :author: Mark Needham
    :twitter: @markhneedham

  4. mneedham revised this gist May 21, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,7 @@
    == How to create relatonships between elements in a collection
    :neo4j-version: 2.1.0-RC1
    :author: Mark Needham
    :twitter: @markhneedham

    This GraphGist answers a http://stackoverflow.com/questions/23779226/how-to-create-relatonship-between-elements-in-collection[Stackoverflow question].

  5. mneedham revised this gist May 21, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,8 @@ We want to create a social network, and have to connect some people. Let's do th

    [source,cypher]
    ----
    FOREACH (name in ["Amanda","Michael", "Max","Magnus","Mark","Peter","Andres"] |
    CREATE (:User {name:name}))
    UNWIND ["Amanda","Michael", "Max","Magnus","Mark","Peter","Andres"] AS name
    CREATE (:User {name:name})
    ----

    //graph
  6. @jexp jexp revised this gist May 21, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    == How to create relatonship between elements in collection
    == How to create relatonships between elements in a collection

    This GraphGist answers a http://stackoverflow.com/questions/23779226/how-to-create-relatonship-between-elements-in-collection[Stackoverflow question].

  7. @jexp jexp revised this gist May 21, 2014. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    == Creating A Sample User Graph
    == How to create relatonship between elements in collection

    This GraphGist answers a http://stackoverflow.com/questions/23779226/how-to-create-relatonship-between-elements-in-collection[Stackoverflow question "How to create relatonship between elements in collection"].
    This GraphGist answers a http://stackoverflow.com/questions/23779226/how-to-create-relatonship-between-elements-in-collection[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.

  8. @jexp jexp revised this gist May 21, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,9 @@
    == Creating A Sample User Graph

    This GraphGist answers a http://stackoverflow.com/questions/23779226/how-to-create-relatonship-between-elements-in-collection[Stackoverflow question "How to create relatonship between elements in collection"].

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

    === Create a few users

    [source,cypher]
  9. @jexp jexp created this gist May 21, 2014.
    26 changes: 26 additions & 0 deletions create_users.adoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    == Creating A Sample User Graph

    === Create a few users

    [source,cypher]
    ----
    FOREACH (name in ["Amanda","Michael", "Max","Magnus","Mark","Peter","Andres"] |
    CREATE (:User {name:name}))
    ----

    //graph

    === Connecting users starting with M

    [source,cypher]
    ----
    MATCH (u:User)
    WHERE u.name =~ 'M.*'
    WITH collect(u) as users
    foreach ( i in range(1,length(users)-1) |
    foreach (u1 in [users[i-1]] | foreach ( u2 in [users[i]] |
    create (u1)-[:knows]-> (u2) ))
    )
    ----

    //graph