neo4j - Create multiple nodes and relationships with parameters -
neo4j - Create multiple nodes and relationships with parameters -
i want create attachments email. have email info array following:
email: {name: 'auniquestring'} attachments: [ {label: 1, filename: 'a.jpg'}, {label: 2, filename: 'b.jpg'}, {label: 3, filename: 'c.jpg'}, ]
if had come in 1 attachment, should work:
match (n:email {name: "auniquestring"}) create (a:attachment {filename: 'a.jpg'}) create (n)-[r:attachment {label: '1'}]->(a)
how create attachment nodes @ 1 time , connect them email node (with single query)?
if pass them in parameters can do:
params:
{ email: {name: 'auniquestring'} attachments: [ {label: 1, filename: 'a.jpg'}, {label: 2, filename: 'b.jpg'}, {label: 3, filename: 'c.jpg'}, ]} create (n:email {name: {email}}) foreach (att in {attachments} | create (a:attachment {filename: att.filename}) create (n)-[:attachment {label: att.label}]->(a) )
foreach works on collections, see here:
http://neo4j.com/blog/oscon-twitter-graph/ http://docs.neo4j.org/chunked/stable/query-foreach.html http://docs.neo4j.org/chunked/stable/cypher-cookbook-pretty-graphs.html neo4j cypher
Comments
Post a Comment