neo4j - Cypher: How to use FOREACH on an array of objects to create multiple nodes and multiple relationships -
i having trouble fetch described in title of question. attempt following string:
foreach (_tabobj in {_tabarray} | match (a:superlabel),(b) a.id = {_parentid} , b.id = _tabobj.id merge (a)-[r:includes]->(b { name : _tabobj.name })
i trying create relationship if not in database , nothing if relationship in database. trying create b node if not in database , nothing if b node in database.
i grateful can offer
how this:
match (a:superlabel {id: {_parentid}}) a, tabarray in {_tabarray} unwind tabarray tabobj match (b {id: tabobj.id) merge (a)-[r:includes]->(b {name: tabobj.name})
i use foreach
last resort ;)
and simpler solution:
match (a:superlabel {id: {_parentid}}), (b) b.id in extract(tabobj in {_tabarray} | tabobj.id) merge (a)-[r:includes]->(b {name: tabobj.name})
an important consideration both of these queries: when matching b
node on id
property database index (if have one) won't used because indexes label / property pair. specifying label b
, if applicable, performance.
Comments
Post a Comment