cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to fetch node & edge data as separate collections?

svincen
Node Link

Neo4j Browser visualizes all nodes + edges if you query: 'match (a:thing),(b:action) return *'

I want that node & edge data, but formatted separately, like:
{
  nodes:['dog','cat','rat'],
  edges:[['dog','does','bite'], ['cat','does','scratch'],['dog','chases','cat']]
}

I'm come up with a monstrous cypher query below... but it only returns (a:thing)-[r:does]-(b:action) and does not return ['dog','chases','cat'] (which would be (a:thing)-[r1:chases]-(a:thing)

Please help.. there must be an easier or more elegant way to fetch separate node/edge data?

 
MATCH (a:thing),(b:action) 
OPTIONAL MATCH (a)-[r]-(b) 
OPTIONAL MATCH (a)-[r1]-(a)
OPTIONAL MATCH (b)-[r2]-(b)
WITH 
COLLECT(DISTINCT a) + COLLECT(DISTINCT b) as elcol, 
COLLECT(DISTINCT r) + COLLECT(DISTINCT r1) + COLLECT(DISTINCT r2) as relcol
UNWIND elcol as ellist
UNWIND relcol as rellist
RETURN
COLLECT(DISTINCT [ellist.name, labels(ellist)]) as els,
COLLECT(DISTINCT [startnode(rellist).name, type(rellist), endnode(rellist).name]) as rels
0 REPLIES 0