Philip Butler
Philip Butler

Reputation: 489

Accessing nodes in path in neo4j without apoc

Can anyone tell me if this is possible? When trying to use

Unwind apoc.coll.pairsMin(nodes(p)) as pair

It throws

Neo.ClientError.Statement.SyntaxError: Unknown function 'apoc.coll.pairsMin' (line 3, column 8 (offset: 99))
"Unwind apoc.coll.pairsMin(nodes(p)) as pair"

If possible I would prefer to find a solution using out of the box software

Upvotes: 1

Views: 269

Answers (2)

cybersam
cybersam

Reputation: 66989

[UPDATED]

This snippet should work:

WITH NODES(p) AS ns
UNWIND [i IN RANGE(0,SIZE(ns)-2) | ns[i..i+2]] AS pair

Upvotes: 1

Dave Bennett
Dave Bennett

Reputation: 11216

Something like this work for you?

// find the path you are interested in
MATCH p=(:Node {name: 'start'})-[*]->(:Node {name: 'end'})

// use reduce to iterate over the relationships
// accumulate the collections of the start and endNode for each relation
RETURN REDUCE (pairs = [], rel in relationships(p) | pairs + [[startNode(rel), endNode(rel)]] ) AS pairs

The equivalent APOC call would look like this

MATCH p=(:Node {name: 'start'})-[*]->(:Node {name: 'end'})
RETURN apoc.coll.pairsMin(nodes(p)) as pairs

Upvotes: 0

Related Questions