Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-22-2020 12:40 PM
I have this graph
I want convert this to a tree in way that it clones Engine node and its children as 2 diff engine nodes one under Train and one under car as it has 2 incoming links
is something like this possible?
Thanks
08-22-2020 09:04 PM
If I understood correctly, you can try this:
Get the id of your Engine node. I recreated your scenario and in my case id = 13.
MATCH (a) where id(a) = 13
CALL apoc.path.spanningTree(a,{maxLevel:2}) YIELD path
return path
Result:
08-22-2020 10:31 PM
Thanks @ameyasoft however I was looking to have 2 diff engine nodes one under car and one under train.
08-22-2020 10:49 PM
Your data model shows one Engine node is connected to both Train and Car nodes. If you need two separate Engines then you should have:
(Train-[]- (Engine {type: "train"})
(Car)-[]-(Engine {type: "car"})
08-23-2020 01:40 AM
I was able to find apoc.convert.toTree()
this solves my issue i get 2 copies of engines
MATCH p=(n:Part {partNumber:"100", revision: "A"})-[:HAS_BOM_PROPERTY|WITH_PART*]->(m) WITH COLLECT(p) AS ps CALL apoc.convert.toTree(ps) yield value RETURN value;
however i need to get rid the intermediate yellow nodes now.
https://run.mocky.io/v3/75583fed-56f5-4c0e-b378-a768ce53b015
08-24-2020 11:18 AM
MATCH (p1:Part)-[r1]->(b:BOM)-[r2]->(p2:Part)
MERGE (p1)-[rBom:BOM]->(p2)
SET rBom = b
DETACH DELETE b
All the sessions of the conference are now available online