concatenate nodes properties

1,126 views
Skip to first unread message

Wei

unread,
Jul 11, 2014, 7:49:34 PM7/11/14
to ne...@googlegroups.com
hi all,

in Neo4j, I am traversing from node n to node m by following child relationship.  there are multiple nodes between node n and m.  each node has a property called dn.  is it possible to concatenate all nodes' property DN along the path in Cypher?  

my neo4j is community v2..1.2.  I am using cypher query like this to get all the paths: match mypath = (n:topsystem) -[*]-> (m:blade) return mypath.

I like to get this done in Cypher!  

Thanks a lot,
Wei

Michael Hunger

unread,
Jul 11, 2014, 9:14:50 PM7/11/14
to ne...@googlegroups.com
match mypath = (n:topsystem) -[*]-> (m:blade) 
return extract(n in nodes(mypath) | n.dn) 

provides you with a collection of the properties

return reduce(a="", n in nodes(mypath) |  a + "," +n.dn) 

with a string where the properties are comma separated



--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wei

unread,
Jul 11, 2014, 10:04:57 PM7/11/14
to ne...@googlegroups.com
Thanks a lot Michael!   This is really nice!

One little thing:

my node dn values are: ie etc yum.repo.d base, I like to build something like this: etc/yum.repo/base, using / as seperator, but there should be NO leading / and NO ending /.  can this be implemented?

Thanks again,
Wei

Michael Hunger

unread,
Jul 12, 2014, 2:40:36 AM7/12/14
to ne...@googlegroups.com
with reduce(a="", n in nodes(mypath) |  a + "," +n.dn) as path
Return substring(path,1,length(path)-1)

Sent from mobile device

Wei

unread,
Jul 12, 2014, 9:14:32 AM7/12/14
to ne...@googlegroups.com
This is cool, thanks a lot Michael!
Reply all
Reply to author
Forward
0 new messages