getting path doesn't fetch nodes properties ? #57

Closed
otite opened this Issue Nov 10, 2012 · 5 comments

Comments

Projects
None yet
3 participants

otite commented Nov 10, 2012

hi !
i'm trying to get the nodes properties for the nodes contained in the array return by Node.path().
but path.nodes[i].data is always empty...
did i miss something ?
cheers,
guillaume

Owner

aseemk commented Nov 10, 2012

That's unfortunately an oddity of Neo4j's REST API — returned paths don't include nodes' and relationships' properties:

http://docs.neo4j.org/chunked/stable/rest-api-graph-algos.html

I agree this is lame. Fortunately, an easy workaround, and probably better at this point anyway, is to get your path via a Cypher query: that will let you specify that you want the full nodes returned as well.

Hope this helps!

otite commented Nov 12, 2012

thanks for the reply... i'm now getting a path like this :

var query = [
'start n=node(0)',
'match path=(n-[r:THEN*..]->x), x-[s]->() ',
'with path,count(s) as lim',
'where lim > 1',
'return path'
].join("\n");

it gives me all the paths from node(0) to nodes that have more than one children.

if i print results[0].nodes, i have the same problem, they don't contain their properties...

Contributor

freeeve commented Nov 12, 2012

You don't want to use .nodes, the path return result is actually an array of nodes and relationships, and their properties are stored in the data key.

Owner

aseemk commented Nov 14, 2012

Sorry I wasn't clear on this -- returned paths in Cypher will still be just a list of node URLs/references. But, Cypher lets you specify that you want the full nodes (or relationships) in a path, via the NODES() function, e.g.:

var query = [
'start n=node(0)',
'match path=(n-[r:THEN*..]->x), x-[s]->() ',
'with path,count(s) as lim',
'where lim > 1',
'return nodes(path)'
].join("\n");

The returned nodes(path) value will now have the full nodes. Hope this helps. More docs:

http://docs.neo4j.org/chunked/1.8/query-function.html#_collection_functions

aseemk closed this Nov 14, 2012

otite commented Nov 20, 2012

thanks a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment