Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

neo4j converting nodes to list of nodes

Tags:

neo4j

cypher

Suppose we have this query:

match (n:Intersection) WHERE NOT (n)<-[:RTREE_REFERENCE]-() RETURN n

It returns nodes, but how can we return it as a LIST of all nodes returned? i.e. [node1, node2, node3]. The procedure I'm using requires an input parameter which needs to be in collections/list format

match (n:Intersection) WHERE NOT (n)<-[:RTREE_REFERENCE]-() with n  CALL spatial.addNodes("network",n) yield node return node

Type mismatch: expected Collection<Node> but was Node 
like image 540
WantIt Avatar asked Mar 12 '23 12:03

WantIt


1 Answers

If you change your query to:

MATCH (n:Intersection) 
WHERE NOT (n)<-[:RTREE_REFERENCE]-() 
RETURN COLLECT(n)

then it will return the list of nodes.

So the second query will look like this:

MATCH (n:Intersection) 
WHERE NOT (n)<-[:RTREE_REFERENCE]-() 
WITH COLLECT(n) AS nodesList
CALL spatial.addNodes("network", nodesList) YIELD node
RETURN node

See https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-collect

like image 87
Sebastian Avatar answered Mar 18 '23 21:03

Sebastian